L1 : 크레인 인형뽑기 게임 Python

jhyunn·2023년 1월 22일
0

Programmers

목록 보기
53/69

L1 : 크레인 인형뽑기 게임 Python

https://school.programmers.co.kr/learn/courses/30/lessons/64061

import numpy as np
def solution(board, moves):
    board = np.array(board).T.tolist() # numpy의 전치를 활용하면 더 직관적
    cnt = 0
    temp = []
    for i in moves:
        if board[i-1] != [0]*len(board[i-1]): # 해당 열이 모두 공백이 아닐 때만 loop
            while 1:    # 앞서 있는 0이 모두 제거되도록 함
                t = board[i-1][0]
                del board[i-1][0]
                if t != 0:
                    break
            temp.append(t)

            if temp[-2:] == [temp[-1]]*2: # 최근 2칸이 마지막1칸x2와 같을 경우 cnt+=2
                del temp[-2:]
                cnt += 2
    return cnt
profile
https://github.com/Sungjeonghyun

0개의 댓글