Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
normalizing solution in Clear category for Keys and Locks by David_Jones
def normalized(s):
n = s.count('\n')
while s.count('\n0') == n:
s = s.replace('\n0', '\n')
s += '\n'
while s.count('0\n') == n:
s = s.replace('0\n', '\n')
s = s.strip().splitlines()
while all(ch == '0' for ch in s[0]):
s.pop(0)
while all(ch == '0' for ch in s[-1]):
s.pop()
return s
def turned(A):
return [''.join(row) for row in zip(*reversed(A))]
def keys_and_locks(lock, some_key):
lock, some_key = normalized(lock), normalized(some_key)
for _ in range(3):
if lock == some_key:
return True
some_key = turned(some_key)
return lock == some_key
May 6, 2019