completes day2, starts day3.

This commit is contained in:
2022-12-04 18:45:41 -05:00
parent f3e85556d7
commit de37379cc0
4 changed files with 95 additions and 0 deletions

52
day2/part1.py Normal file
View File

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