-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path[프로그래머스] 이나정_프렌즈4블록.py
37 lines (33 loc) · 1.13 KB
/
[프로그래머스] 이나정_프렌즈4블록.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
remove_block = []
totalMap = []
def fallBlock(n):
global remove_block, totalMap
for block in remove_block:
totalMap[block[0]][block[1]] = ""
for i in range(n):
count = totalMap[i].count("")
totalMap[i] = [x for x in totalMap[i] if x != ""]
totalMap[i] += ["" for _ in range(count)]
def removable(m, n):
global remove_block, totalMap
remove_block.clear()
for x in range(m-1):
for y in range(n-1):
if totalMap[x][y] != "" and totalMap[x][y] == totalMap[x][y+1] == totalMap[x+1][y] == totalMap[x+1][y+1]:
for pair in [[x, y], [x+1, y], [x, y+1], [x+1, y+1]]:
if pair not in remove_block:
remove_block.append(pair)
return True if remove_block else False
def solution(m, n, board):
global totalMap
for x in range(n):
temp = []
for y in range(m):
temp.append(board[m-y-1][x])
totalMap.append(temp)
answer = 0
while(removable(n, m)):
removable(n, m)
answer += len(remove_block)
fallBlock(n)
return answer