Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
resolve solution in Clear category for Keys and Locks by ndj_ys
def keys_and_locks(lock, some_key):
"""remove zero of lock and some_key"""
lock_rz = ["".join(j) for j in zip(*[i for i in lock.split() \
if i != len(i) * "0"]) if list(j) != len(j) * ["0"]]
key_rz = ["".join(j) for j in zip(*[i for i in some_key.split() \
if i != len(i) * "0"]) if list(j) != len(j) * ["0"]]
for i in range(4):
if key_rz == lock_rz:
return True
else:
key_rz = ["".join(i[::-1]) for i in zip(*key_rz)]
else:
return False
if __name__ == '__main__':
print("Example:")
print(keys_and_locks('''
0##0
0##0
00#0
00##
00##''',
'''
00000
000##
#####
##000
00000'''))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert keys_and_locks('''
0##0
0##0
00#0
00##
00##''',
'''
00000
000##
#####
##000
00000''') == True
assert keys_and_locks('''
###0
00#0''',
'''
00000
00000
#0000
###00
0#000
0#000''') == False
assert keys_and_locks('''
0##0
0#00
0000''',
'''
##000
#0000
00000
00000
00000''') == True
assert keys_and_locks('''
###0
0#00
0000''',
'''
##00
##00''') == False
print("Coding complete? Click 'Check' to earn cool rewards!")
Sept. 19, 2018
Comments: