-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpg_67256
More file actions
63 lines (53 loc) · 1.54 KB
/
pg_67256
File metadata and controls
63 lines (53 loc) · 1.54 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# https://school.programmers.co.kr/learn/courses/30/lessons/67256
# 키패드 누르기
def solution(numbers, hand):
# 두 엄지의 거리가 같다면 오른손잡이는 오른손, 왼손은 왼손
# 1, 4, 7, * = L
# 3, 6, 8, # = R
# 2, 5, 8, 0 = 더 가까운 손가락으로
dic = {
1: [0, 0],
2: [0, 1],
3: [0, 2],
4: [1, 0],
5: [1, 1],
6: [1, 2],
7: [2, 0],
8: [2, 1],
9: [2, 2],
"*": [3, 0],
0: [3, 1],
"#": [3, 2]
}
def distance(now, dest):
return abs(now[0]-dest[0])+abs(now[1]-dest[1])
result = ""
left = dic["*"]
right = dic["#"]
for number in numbers:
if number in [1, 4, 7]:
left = dic[number]
result += "L"
continue
if number in [3, 6, 9]:
right = dic[number]
result += "R"
continue
destination = dic[number]
leftDistance = distance(left, destination)
rightDistance = distance(right, destination)
# 왼손이 더 가까움
if leftDistance < rightDistance:
left = destination
result += "L"
elif leftDistance > rightDistance:
right = destination
result += "R"
else:
if hand == "right":
right = destination
result += "R"
else:
left = destination
result += "L"
return result