💡 Python 3
크레인 인형뽑기 게임 [Link]
def solution(board, moves):
answer = 0
check = [0]
for i in moves:
for b in board:
if b[i-1] is not 0:
if check[-1] == b[i-1]:
check.pop()
answer += 2
b[i-1] = 0
break
else:
check.append(b[i-1])
b[i-1] = 0
break
return answer
filter
함수에 대해서 알게 되었다.
def solution(board, moves):
cols = list(map(lambda x: list(filter(lambda y: y > 0, x)), zip(*board)))
a, s = 0, [0]
for m in moves:
if len(cols[m - 1]) > 0:
if (d := cols[m - 1].pop(0)) == (l := s.pop()):
a += 2
else:
s.extend([l, d])
return a