This repository was archived by the owner on Apr 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2.py
95 lines (83 loc) · 2.14 KB
/
day2.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
with open("input.txt") as f:
input = f.read().splitlines()
moves = {
"A":"rock",
"B":"paper",
"C":"scissors",
"X":"rock",
"Y":"paper",
"Z":"scissors",
}
outcomes = {
"X":"lost",
"Y":"draw",
"Z":"win"
}
# paper beats rock B -> X, Y -> A
# rock beats scissors A -> Z, X -> C
# scissors beats paper C -> Y, Z -> B
hand_points = {
"rock":1,
"paper":2,
"scissors":3
}
outcome_points = {
"lost": 0,
"draw":3,
"win":6
}
def decide_outcome(player, opponent):
if player == opponent:
return "draw"
elif player == "rock" and opponent == "scissors":
return "win"
elif player == "paper" and opponent == "rock":
return "win"
elif player == "scissors" and opponent == "paper":
return "win"
else:
return "lost"
def fix_outcome(opponent, outcome):
if outcome == "draw":
return opponent
elif outcome == "win":
if opponent == "scissors":
return "rock"
elif opponent == "rock":
return "paper"
elif opponent == "paper":
return "scissors"
elif outcome == "lost":
if opponent == "scissors":
return "paper"
elif opponent == "rock":
return "scissors"
elif opponent == "paper":
return "rock"
def decide_round(line):
player = moves[line[2]]
opponent = moves[line[0]]
outcome = decide_outcome(player, opponent)
hand_point = hand_points[player]
outcome_point = outcome_points[outcome]
round_point = hand_point + outcome_point
print(player, opponent, outcome, round_point)
return round_point
def fix_round(line):
print(line)
outcome_decision = outcomes[line[2]]
opponent = moves[line[0]]
player = fix_outcome(opponent, outcome_decision)
hand_point = hand_points[player]
outcome_point = outcome_points[outcome_decision]
round_point = hand_point + outcome_point
print(player, opponent, outcome_decision, round_point)
return round_point
total = 0
for line in input:
total += decide_round(line)
print(total)
total = 0
for line in input:
total += fix_round(line)
print(total)