반응형
https://programmers.co.kr/learn/courses/30/lessons/60059?language=python3
def solution(key, lock):
m = len(key)
n = len(lock)
def rotate():
rkey = [[0 for _ in range(m)] for _ in range(m)]
for i in range(m):
for j in range(m):
rkey[j][-i+m-1] = key[i][j]
return rkey
for _ in range(4):
# adjust the key's position
for x in range(n+m):
for y in range(n+m):
tried = [[0 for _ in range(n+2*m)] for _ in range(n+2*m)]
for i in range(n):
for j in range(n):
tried[i+m][j+m] = lock[i][j]
# sum
for i in range(m):
for j in range(m):
tried[i+x][j+y] += key[i][j]
#check
stop = False
for i in range(n):
for j in range(n):
if tried[i+m][j+m] != 1:
stop = True
break
if stop: break
if not stop:
return True
key = rotate()
return False
댓글