-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenge.py
70 lines (56 loc) · 1.72 KB
/
challenge.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
import sys
class Round:
def __init__ (self, oponent_play, your_play):
self.oponent_play = oponent_play
self.your_play = your_play
self.score = 0
def scoreCalculation(self):
pts = 0
#Score for the shape used
if self.your_play == 'R':
pts = pts + 1
elif self.your_play == 'P':
pts = pts + 2
else:
pts = pts + 3
#Score for the outcome of the round
if self.oponent_play == self.your_play:
#It's a Draw
pts = pts + 3
elif self.oponent_play == 'R' and self.your_play == 'P' or self.oponent_play == 'P' and self.your_play == 'S' or self.oponent_play == 'S' and self.your_play == 'R':
#You won
pts = pts + 6
else:
#You lose
pts = pts + 0
self.score = pts
file = open('input.txt', 'r')
lines = file.readlines()
totalScore1 = 0
totalScore2 = 0
for line in lines:
l = line.split()
#Solve part 1
l[0] = 'R' if l[0]=='A' else 'P' if l[0]=='B' else 'S'
l[1] = 'R' if l[1]=='X' else 'P' if l[1]=='Y' else 'S'
r = Round(l[0], l[1])
r.scoreCalculation()
totalScore1 = totalScore1 + r.score
#Solve part 2
if l[1] == 'R':
#need to lose
l[1] = 'P' if l[0]=='S' else 'R' if l[0]=='P' else 'S'
elif l[1] == 'P':
#need to end the round in a draw
l[1] = 'P' if l[0]=='P' else 'R' if l[0]=='R' else 'S'
else:
#need to win
l[1] = 'S' if l[0]=='P' else 'P' if l[0]=='R' else 'R'
r2 = Round(l[0], l[1])
r2.scoreCalculation()
totalScore2 = totalScore2 + r2.score
#Part 1 result
print(totalScore1)
#Part 2 result
print(totalScore2)
exit()