-
Notifications
You must be signed in to change notification settings - Fork 0
/
day2.py
64 lines (55 loc) · 1.34 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
shapePoints = {
"X": 1,
"Y": 2,
"Z": 3,
"A": 1,
"B": 2,
"C": 3
}
winOrLosePoints = {
-1: 0,
0: 3,
1: 6
}
result = {
"X": -1,
"Y": 0,
"Z": 1,
}
def gameRound(played):
if shapePoints[played[0]] == shapePoints[played[1]]:
return 0
if shapePoints[played[0]] - shapePoints[played[1]] == -1:
return 1
if shapePoints[played[0]] - shapePoints[played[1]] == 2:
return 1
else:
return -1
def figurePointsOfMustPlayedShape(column):
if result[column[1]] == 0:
return shapePoints[column[0]]
if result[column[1]] == 1:
return (shapePoints[column[0]] % 3) + 1
else:
points = shapePoints[column[0]] - 1
if points == 0:
return 3
return points
def scoreStrategy1(lines):
score = 0
for l in lines:
played = l.strip().split(' ')
score += winOrLosePoints[gameRound(played)] + shapePoints[played[1]]
return score
def scoreStrategy2(lines):
score = 0
for l in lines:
columns = l.strip().split(' ')
score += winOrLosePoints[result[columns[1]]] + figurePointsOfMustPlayedShape(columns)
return score
if __name__ == '__main__':
f = open('./day2_input.txt', 'r')
lines = f.readlines()
print(scoreStrategy1(lines))
print(scoreStrategy2(lines))
f.close()