-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2.py
71 lines (63 loc) · 1.99 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
from types import SimpleNamespace
# access the points with dot notation
points = {
'ROCK': 1,
'PAPER': 2,
'SISSOR': 3,
'LOST': 0,
'DRAW': 3,
'WIN': 6,
}
p = SimpleNamespace(**points)
# access the rules with dot notation
rules = {
'ROCK': 'ROCK',
'PAPER': 'PAPER',
'SISSOR': 'SISSOR',
}
r = SimpleNamespace(**rules)
# replace A,B,C and X,Y,Z with rock, paper, sissor
def getValue(player):
if (player == 'A' or player == 'X'):
return r.ROCK
if (player == 'B' or player == 'Y'):
return r.PAPER
if (player == 'C' or player == 'Z'):
return r.SISSOR
# check win, loss, or draw
def rockPaperSissor(foe, you):
if (getValue(you) == r.ROCK):
if (getValue(foe) == r.ROCK):
return [p.ROCK + p.DRAW, p.ROCK + p.DRAW]
elif (getValue(foe) == r.PAPER):
return [p.PAPER + p.WIN, p.ROCK + p.LOST]
elif (getValue(foe) == r.SISSOR):
return [p.SISSOR + p.LOST, p.ROCK + p.WIN]
elif (getValue(you) == r.PAPER):
if (getValue(foe) == r.ROCK):
return [p.ROCK + p.LOST, p.PAPER + p.WIN]
elif (getValue(foe) == r.PAPER):
return [p.PAPER + p.DRAW, p.PAPER + p.DRAW]
elif (getValue(foe) == r.SISSOR):
return [p.SISSOR + p.WIN, p.PAPER + p.LOST]
elif (getValue(you) == r.SISSOR):
if (getValue(foe) == r.ROCK):
return [p.ROCK + p.WIN, p.SISSOR + p.LOST]
elif (getValue(foe) == r.PAPER):
return [p.PAPER + p.LOST, p.SISSOR + p.WIN]
elif (getValue(foe) == r.SISSOR):
return [p.SISSOR + p.DRAW, p.SISSOR + p.DRAW]
# read input
input = open('input.txt', 'r')
lines = input.readlines()
opponentTotal = 0
yourTotal = 0
for line in lines:
s = line[:3].split(' ')
result = rockPaperSissor(s[0], s[1])
opponentTotal = opponentTotal + result[0]
yourTotal = yourTotal + result[1]
# part one
print('Opponent\'s total score: ', opponentTotal)
print('Your total score: ', yourTotal)
# part two