-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfriends4block.py
34 lines (30 loc) · 897 Bytes
/
friends4block.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
def pop_num(b, m, n):
pop_set = set()
# search
for i in range(1, n):
for j in range(1, m):
if b[i][j] == b[i - 1][j - 1] == b[i - 1][j] == b[i][j - 1] != '_':
pop_set |= {(i, j), (i - 1, j - 1), (i - 1, j), (i, j - 1)}
print(pop_set)
# set_board
for i, j in pop_set:
b[i][j] = 0
for i, row in enumerate(b):
print(row)
empty = ['_'] * row.count(0)
print(empty)
b[i] = empty + [block for block in row if block != 0]
print(b[i])
return len(pop_set)
def solution(m, n, board):
count = 0
b = list(map(list, zip(*board)))
print(b)
while True:
pop = pop_num(b, m, n)
if pop == 0:
return count
count += pop
if __name__ == '__main__':
answer = solution(4, 5, ['CCBDE', 'AAADE', 'AAABF', 'CCBBF'])
print('출력값: ', answer)