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
35
36
| def solution(numbers, hand):
num_1 = [1,4,7,'*']
num_2 = [2,5,8,0]
num_3 = [3,6,9,'#']
left_hand = [0, num_1.index('*')]
right_hand = [2, num_3.index('#')]
answer = ''
for num in numbers:
if num in num_1:
left_hand = [0, num_1.index(num)]
answer += 'L'
elif num in num_3:
right_hand = [2, num_3.index(num)]
answer += 'R'
else:
des = [1, num_2.index(num)]
left_dis = sum([abs(i - j) for i, j in zip(left_hand, des)])
right_dis = sum([abs(i - j) for i, j in zip(right_hand, des)])
if left_dis > right_dis:
right_hand = [1, num_2.index(num)]
answer += 'R'
elif left_dis < right_dis:
left_hand = [1, num_2.index(num)]
answer += 'L'
else:
if hand == 'right':
righ_hand = [1, num_2.index(num)]
answer += 'R'
else:
left_hand = [1, num_2.index(num)]
answer += 'L'
return answer
|