-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2_rps.py
107 lines (89 loc) · 2.69 KB
/
day2_rps.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
95
96
97
98
99
100
101
102
103
104
105
106
107
import sys
plays = []
scores = {
"A": 1,
"B": 2,
"C": 3,
"X": 1,
"Y": 2,
"Z": 3,
"loss": 0,
"draw": 3,
"win": 6
}
def ParseInput(filename):
global plays
with open(filename) as f:
plays = f.readlines()
def CalculateScorePart1(play1, play2):
current_score = 0
result = None
current_score += scores[play2]
if play1 == "A" and play2 == "X":
result = "draw"
elif play1 == "A" and play2 == "Y":
result = "win"
elif play1 == "A" and play2 == "Z":
result = "loss"
elif play1 == "B" and play2 == "X":
result = "loss"
elif play1 == "B" and play2 == "Y":
result = "draw"
elif play1 == "B" and play2 == "Z":
result = "win"
elif play1 == "C" and play2 == "X":
result = "win"
elif play1 == "C" and play2 == "Y":
result = "loss"
elif play1 == "C" and play2 == "Z":
result = "draw"
else:
result = "wtf"
print(f"play1={play1}", f"play2={play2}", f"{len(play1)}", f"{len(play2)}")
return current_score + scores[result]
def CalculateScorePart2(play1, play2):
current_score = 0
result = None
# current_score += scores[play2]
if play1 == "A" and play2 == "X":
current_score += scores["C"]
result = "loss"
elif play1 == "A" and play2 == "Y":
current_score += scores["A"]
result = "draw"
elif play1 == "A" and play2 == "Z":
current_score += scores["B"]
result = "win"
elif play1 == "B" and play2 == "X":
current_score += scores["A"]
result = "loss"
elif play1 == "B" and play2 == "Y":
current_score += scores["B"]
result = "draw"
elif play1 == "B" and play2 == "Z":
current_score += scores["C"]
result = "win"
elif play1 == "C" and play2 == "X":
current_score += scores["B"]
result = "loss"
elif play1 == "C" and play2 == "Y":
current_score += scores["C"]
result = "draw"
elif play1 == "C" and play2 == "Z":
current_score += scores["A"]
result = "win"
else:
result = "wtf"
print(f"play1={play1}", f"play2={play2}", f"{len(play1)}", f"{len(play2)}")
current_score += scores[result]
return current_score
def main(filename):
global plays
ParseInput(filename)
total_score = 0
for play in plays:
play1, play2 = play.split(' ')
total_score += CalculateScorePart2(play1, play2.strip())
print(total_score)
if __name__ == "__main__":
main(sys.argv[1])