문제
![](https://velog.velcdn.com/images/cosmos/post/f6ea88f6-cde9-4b7b-a450-a26465fb3dfd/image.png)
코드
def up(start: list, position: list):
if start[1] != (position[1]-1) / 2:
start[1] += 1
def down(start: list, position: list):
if start[1] != (position[1] - 1) / 2 * -1:
start[1] -= 1
def left(start: list, position: list):
if start[0] != (position[0] - 1) / 2 * -1:
start[0] -= 1
def right(start: list, position: list):
if start[0] != (position[0] - 1) / 2:
start[0] += 1
def solution(keyinput: list, board: list) -> list:
start = [0, 0]
for x in keyinput:
if x == 'up':
up(start, board)
elif x == 'down':
down(start, board)
elif x == 'left':
left(start, board)
elif x == 'right':
right(start, board)
return start
if __name__ == '__main__':
print(solution(["left", "right", "up", "right", "right"], [11, 11]))
print(solution(["down", "down", "down", "down", "down"], [7, 9]))
결과
![](https://velog.velcdn.com/images/cosmos/post/6df94271-e6c3-4f1d-8c2b-ed684c5c61cc/image.png)
출처 & 깃허브
programmers
깃허브