-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path자물쇠와열쇠.py
46 lines (38 loc) · 1.21 KB
/
자물쇠와열쇠.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def rotate_a_matrix_by_90_degree(a):
n = len(a)
m = len(a[0])
result = [[0]*n for _ in range(m)]
for i in range(n):
for j in range(m):
result[j][n-i-1] = a[i][j]
return result
def check(new_lock):
lock_length = len(new_lock) // 3
for i in range(lock_length, lock_length*2):
for j in range(lock_length, lock_length*2):
if new_lock[i][j] != 1:
return False
return True
def solution(key, lock):
n = len(lock)
m = len(key)
new_lock = [[0]*(n*3) for _ in range(n*3)]
for i in range(n):
for j in range(n):
new_lock[i+n][j+n] = lock[i][j]
for rotation in range(4):
key = rotate_a_matrix_by_90_degree(key)
for x in range(n*2):
for y in range(n*2):
for i in range(m):
for j in range(m):
new_lock[x+i][y+j] += key[i][j]
if check(new_lock):
return True
for i in range(m):
for j in range(m):
new_lock[x+i][y+j] -= key[i][j]
return False
key = [[0,0,0],[1,0,0],[0,1,1]]
lock= [[1,1,1],[1,1,0],[1,0,1]]
print(solution(key, lock))