day2 part 1 complete.
This commit is contained in:
2500
day2/input.txt
Normal file
2500
day2/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
52
day2/main.py
52
day2/main.py
@@ -0,0 +1,52 @@
|
|||||||
|
import datetime
|
||||||
|
print(datetime.datetime.now())
|
||||||
|
input = open("./input.txt", "r")
|
||||||
|
|
||||||
|
gameResult = {
|
||||||
|
"win": 6,
|
||||||
|
"tie": 3,
|
||||||
|
"lose": 0
|
||||||
|
}
|
||||||
|
|
||||||
|
throws = {
|
||||||
|
"rock": 1,
|
||||||
|
"paper": 2,
|
||||||
|
"scissors": 3
|
||||||
|
}
|
||||||
|
|
||||||
|
rpsThrow = {
|
||||||
|
"A": "rock",
|
||||||
|
"B": "paper",
|
||||||
|
"C": "scissors",
|
||||||
|
"X": "rock",
|
||||||
|
"Y": "paper",
|
||||||
|
"Z": "scissors"
|
||||||
|
}
|
||||||
|
|
||||||
|
total = 0
|
||||||
|
|
||||||
|
def determineWinner(opponent, self):
|
||||||
|
if (opponent == self):
|
||||||
|
return "tie"
|
||||||
|
if (throws[opponent] == throws["rock"]):
|
||||||
|
if (throws[self] == throws["paper"]):
|
||||||
|
return "win"
|
||||||
|
if (throws[opponent] == throws["paper"]):
|
||||||
|
if (throws[self] == throws["scissors"]):
|
||||||
|
return "win"
|
||||||
|
if (throws[opponent] == throws["scissors"]):
|
||||||
|
if (throws[self] == throws["rock"]):
|
||||||
|
return "win"
|
||||||
|
return "lose"
|
||||||
|
|
||||||
|
def calculateScore(game):
|
||||||
|
foe = rpsThrow[game[0]]
|
||||||
|
me = rpsThrow[game[2]]
|
||||||
|
result = determineWinner(foe, me)
|
||||||
|
return gameResult[result] + throws[rpsThrow[game[2]]]
|
||||||
|
|
||||||
|
for line in input:
|
||||||
|
total = total + calculateScore(line)
|
||||||
|
|
||||||
|
print(total)
|
||||||
|
print(datetime.datetime.now())
|
||||||
3
day2/test.txt
Normal file
3
day2/test.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
A Y
|
||||||
|
B X
|
||||||
|
C Z
|
||||||
Reference in New Issue
Block a user