-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday02.py
More file actions
35 lines (28 loc) · 1023 Bytes
/
Copy pathday02.py
File metadata and controls
35 lines (28 loc) · 1023 Bytes
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
player_score = {"X": 1, "Y": 2, "Z": 3}
table_lookup = {
"A": {"X": 3, "Y": 6, "Z": 0},
"B": {"X": 0, "Y": 3, "Z": 6},
"C": {"X": 6, "Y": 0, "Z": 3},
}
result_lookup = {
"A": {"X": "Z", "Y": "X", "Z": "Y"},
"B": {"X": "X", "Y": "Y", "Z": "Z"},
"C": {"X": "Y", "Y": "Z", "Z": "X"},
}
def score_round(opponent: str, me: str) -> int:
assert me in player_score.keys()
assert opponent in table_lookup.keys()
score = player_score[me] + table_lookup[opponent][me]
return score
with open("day02.txt", "r") as file:
total_score = 0
score_part2 = 0
for x in file.readlines():
if len(x) > 0:
round = x.split(" ")
total_score += score_round(round[0].strip(), round[1].strip())
# for part two, lookup what we should play to get the result we want
our_play = result_lookup[round[0].strip()][round[1].strip()]
score_part2 += score_round(round[0].strip(), our_play)
print(total_score)
print(score_part2)