Files
advent_of_code/day2/main.py
2022-12-03 00:07:49 -05:00

52 lines
1.1 KiB
Python

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())