레벨1 문제
def solution(numbers, hand):
answer = ''
arr = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [3, 1], [3, 0], [3, 2]]
left, right = arr[-2], arr[-1]
for n in numbers:
if n == 0:
n = 10
if ( n in [1, 4, 7] ):
left = arr[n-1]
answer += 'L'
elif ( n in [3, 6, 9] ):
right = arr[n-1]
answer += 'R'
else:
left_dis = abs(left[0] - arr[n-1][0]) + abs(left[1] - arr[n-1][1])
right_dis = abs(right[0] - arr[n-1][0]) + abs(right[1] - arr[n-1][1])
if ( left_dis < right_dis ):
left = arr[n-1]
answer += 'L'
elif ( left_dis > right_dis ):
right = arr[n-1]
answer += 'R'
# 거리가 같음
else:
if ( hand == 'left' ):
left = arr[n-1]
answer += 'L'
else:
right = arr[n-1]
answer += 'R'
return answer