반응형
def solution(numbers, hand):
standard = 12
numbers_location = {}
left_default_location = [1, 4, 7]
right_default_location = [3, 6, 9]
left_location = [0, 3]
right_location = [2, 3]
x_count = 0
y_count = 0
result = []
for idx in range(standard):
if idx !=0 and int(idx) % 3 == 0:
x_count = 0
y_count = y_count + 1
numbers_location[idx+1] = [x_count, y_count]
x_count = x_count + 1
else:
if idx+1 != 11:
numbers_location[idx+1] = [x_count, y_count]
x_count = x_count + 1
else:
numbers_location[0] = [x_count, y_count]
x_count = x_count + 1
for number in numbers:
move_finger = numbers_location[number]
if number in left_default_location:
left_location = move_finger
result.append('L')
elif number in right_default_location:
right_location = move_finger
result.append('R')
else:
x_move_0 = (move_finger[0] - left_location[0]) if (move_finger[0] - left_location[0]) > 0 else -(move_finger[0] - left_location[0])
y_move_1 = (move_finger[1] - left_location[1]) if (move_finger[1] - left_location[1]) > 0 else -(move_finger[1] - left_location[1])
x_move_1 = (move_finger[0] - right_location[0]) if (move_finger[0] - right_location[0]) > 0 else -(move_finger[0] - right_location[0])
y_move_2 = (move_finger[1] - right_location[1]) if (move_finger[1] - right_location[1]) > 0 else -(move_finger[1] - right_location[1])
left_move_count = x_move_0 + y_move_1
right_move_count = x_move_1 + y_move_2
if left_move_count == right_move_count:
hand_upper = hand[:1].upper()
if hand_upper == 'R':
result.append(hand_upper)
right_location = move_finger
else:
result.append(hand_upper)
left_location = move_finger
elif left_move_count > right_move_count:
right_location = move_finger
result.append('R')
else:
left_location = move_finger
result.append('L')
answer = ''.join(result)
return answer반응형
'삽집하는 개발들 > 알고리즘' 카테고리의 다른 글
| [17일차][프로그래머스][140108]문자열 나누기 (0) | 2023.07.04 |
|---|---|
| [16일차][프로그래머스][2019 카카오 - 64061]크레인 인형뽑기 게임 (0) | 2023.07.03 |
| [14일차][프로그래머스][160586]대충 만든 자판 (0) | 2023.06.27 |
| [14일차][프로그래머스][155652]둘만의 암호 (0) | 2023.06.27 |
| [13일차][프로그래머스][2021 카카오 - 72410]신규 아이디 추천 (0) | 2023.06.26 |