-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday02_total_score.py
48 lines (37 loc) · 1.03 KB
/
day02_total_score.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
SELECTION_MAP = {
"A": "ROCK",
"X": "ROCK",
"B": "PAPER",
"Y": "PAPER",
"C": "SCISSORS",
"Z": "SCISSORS",
}
SELECTION_SCORES = {
"ROCK": 1,
"PAPER": 2,
"SCISSORS": 3
}
def get_score(opponent_choice, your_choice):
score = SELECTION_SCORES[your_choice]
if opponent_choice == your_choice:
return score + 3
is_win = False
if your_choice == "ROCK" and opponent_choice == "SCISSORS":
is_win = True
elif your_choice == "PAPER" and opponent_choice == "ROCK":
is_win = True
elif your_choice == "SCISSORS" and opponent_choice == "PAPER":
is_win = True
if is_win:
return score + 6
return score
def main():
with open('data/day02_rps_strategy.data') as f:
total_score = 0
for row in f:
opponent_choice = SELECTION_MAP[row[0]]
your_choice = SELECTION_MAP[row[2]]
total_score += get_score(opponent_choice, your_choice)
print(f"answer: {total_score}")
if __name__ == "__main__":
main()