-
Notifications
You must be signed in to change notification settings - Fork 0
/
d2p2.py
81 lines (62 loc) · 1.76 KB
/
d2p2.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from typing import List, Tuple
map_my_input_to_goal = {
"X": "eaten",
"Y": "ignored",
"Z": "eater",
}
map_my_choice_to_score = {
"worm": 1,
"bird": 2,
"cat": 3,
}
map_their_input_to_choice = {
"A": "worm",
"B": "bird",
"C": "cat",
}
map_their_choice_and_my_goal_to_my_choice = {
"cat": {
"ignored": "cat",
"eaten": "bird",
"eater": "worm",
},
"bird": {
"ignored": "bird",
"eaten": "worm",
"eater": "cat",
},
"worm": {
"ignored": "worm",
"eaten": "cat",
"eater": "bird",
},
}
map_result_to_score = {
"eaten": 0,
"ignored": 3,
"eater": 6,
}
def parse_input(message: str) -> List[Tuple[str, str]]:
# PROMPT: parse into array of lines and then split each by space
return [line.split(" ") for line in message.splitlines()]
def compute_answer(inputs: List[Tuple[str, str]]) -> int:
total_score = 0
for input in inputs:
their_input = input[0]
my_input = input[1]
# PROMPT: map their input to choice
their_choice = map_their_input_to_choice[their_input]
# PROMPT: map my input to goal
my_goal = map_my_input_to_goal[my_input]
# PROMPT: map their choice and my goal to my choice
my_choice = map_their_choice_and_my_goal_to_my_choice[their_choice][my_goal]
# PROMPT: map my choice to score
my_score = map_my_choice_to_score[my_choice]
# PROMPT: add my score to total score
total_score += my_score
result = my_goal
# PROMPT: map result to score
result_score = map_result_to_score[result]
# PROMPT: add result score to total score
total_score += result_score
return total_score