Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save inspirit941/117d0b7ee83bc4bbd5ac61db033bd51f to your computer and use it in GitHub Desktop.
Save inspirit941/117d0b7ee83bc4bbd5ac61db033bd51f to your computer and use it in GitHub Desktop.
def rotate(maps):
return [list(reversed(i)) for i in zip(*maps)]
def solution(key, lock):
hole = 0
for y in range(len(lock)):
for x in range(len(lock[0])):
if lock[y][x] == 0:
hole += 1
for _ in range(4):
for start_y in range(-len(key)+1, len(lock)):
for start_x in range(-len(key)+1, len(lock[0])):
# 자물쇠와 lock 일치하는 개수 / match여부
check = 0
match = True
for y in range(start_y, start_y + len(key)):
if y < 0 or y >= len(lock):
continue
for x in range(start_x, start_x + len(key[0])):
if x < 0 or x >= len(lock[0]):
continue
# 자물쇠 돌기와 열쇠 돌기가 만나는 경우
if lock[y][x] == 1 and key[y - start_y][x - start_x] == 1:
match = False
break
# 자물쇠 돌기와 홈 구멍이 일치하는 경우
elif lock[y][x] == 0 and key[y - start_y][x - start_x] == 1:
check += 1
# 더 체크할 필요 없이 자물쇠와 열쇠가 맞지 않는 경우
if not match:
break
# 자물쇠 돌기와 홈 구멍 개수가 일치하는 경우
if match and check == hole:
return True
key = rotate(key)
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment