Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Keys and Locks by frbrgeorge
import itertools
def keys_and_locks(lock, some_key):
# This works on one-hole keyholes/keys
# Shapes like ";" can have false positives
L = [s for s in lock.strip().split() if "#" in s]
K = [s for s in some_key.strip().split() if "#" in s]
L = [s for s in zip(*reversed(L)) if "#" in s]
for i in range(4):
K = [s for s in zip(*reversed(K)) if "#" in s]
if K==L:
return True
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!")
Dec. 26, 2018