|
| 1 | +# 내 풀이 실패 |
| 2 | +def solution(numbers, hand): |
| 3 | + answer = '' |
| 4 | + |
| 5 | + current_left_hand_number = '*' |
| 6 | + current_right_hand_number = '#' |
| 7 | + |
| 8 | + number_map_dict = { |
| 9 | + 1: [0, 0], |
| 10 | + 2: [0, 1], |
| 11 | + 3: [0, 2], |
| 12 | + |
| 13 | + 4: [1, 0], |
| 14 | + 5: [1, 1], |
| 15 | + 6: [1, 2], |
| 16 | + |
| 17 | + 7: [2, 0], |
| 18 | + 8: [2, 1], |
| 19 | + 9: [2, 2], |
| 20 | + |
| 21 | + '*': [3, 0], |
| 22 | + 0: [3, 1], |
| 23 | + '#': [3, 2], |
| 24 | + } |
| 25 | + |
| 26 | + for current_number in numbers: |
| 27 | + if current_number == 1 or current_number == 4 or current_number == 7: |
| 28 | + answer += 'L' |
| 29 | + current_left_hand_number = current_number |
| 30 | + elif current_number == 3 or current_number == 6 or current_number == 9: |
| 31 | + answer += 'R' |
| 32 | + current_right_hand_number = current_number |
| 33 | + else: |
| 34 | + left_hand_distance = \ |
| 35 | + abs(number_map_dict[current_number][0] - number_map_dict[current_left_hand_number][0]) \ |
| 36 | + + abs(number_map_dict[current_number][1] - number_map_dict[current_left_hand_number][1]) |
| 37 | + |
| 38 | + right_hand_distance = \ |
| 39 | + abs(number_map_dict[current_number][0] - number_map_dict[current_right_hand_number][0]) \ |
| 40 | + + abs(number_map_dict[current_number][1] - number_map_dict[current_right_hand_number][1]) |
| 41 | + |
| 42 | + if left_hand_distance == right_hand_distance: |
| 43 | + if hand == 'left': |
| 44 | + answer += 'L' |
| 45 | + current_left_hand_number = current_number |
| 46 | + else: |
| 47 | + answer += 'R' |
| 48 | + current_right_hand_number = current_number |
| 49 | + elif left_hand_distance < right_hand_distance: |
| 50 | + answer += 'L' |
| 51 | + current_left_hand_number = current_number |
| 52 | + else: |
| 53 | + answer += 'R' |
| 54 | + current_right_hand_number = current_number |
| 55 | + return answer |
| 56 | + |
| 57 | + |
| 58 | +print(solution([1, 3, 4, 5, 8, 2, 1, 4, 5, 9, 5], "right")) |
| 59 | +print(solution([1, 3, 4, 5, 8, 2, 1, 4, 5, 9, 5], "right") == "LRLLLRLLRRL") |
| 60 | + |
| 61 | +print(solution([7, 0, 8, 2, 8, 3, 1, 5, 7, 6, 2], "left")) |
| 62 | +print(solution([7, 0, 8, 2, 8, 3, 1, 5, 7, 6, 2], "left") == "LRLLRRLLLRR") |
| 63 | + |
| 64 | +print(solution([1, 2, 3, 4, 5, 6, 7, 8, 9, 0], "right")) |
| 65 | +print(solution([1, 2, 3, 4, 5, 6, 7, 8, 9, 0], "right") == "LLRLLRLLRL") |
0 commit comments