74 lines
1.7 KiB
Python
74 lines
1.7 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
|
|
}
|
|
|
|
desiredOutcomeMap = {
|
|
"X": "lose",
|
|
"Y": "tie",
|
|
"Z": "win"
|
|
}
|
|
|
|
opponentThrowMap = {
|
|
"A": "rock",
|
|
"B": "paper",
|
|
"C": "scissors"
|
|
}
|
|
|
|
def determineThrow(opponent, desiredOutcome):
|
|
if (opponent == "rock"):
|
|
if (desiredOutcome == "win"):
|
|
return "paper"
|
|
if (desiredOutcome == "lose"):
|
|
return "scissors"
|
|
return "rock"
|
|
if (opponent == "scissors"):
|
|
if (desiredOutcome == "win"):
|
|
return "rock"
|
|
if (desiredOutcome == "lose"):
|
|
return "paper"
|
|
return "scissors"
|
|
if (desiredOutcome == "win"):
|
|
return "scissors"
|
|
if (desiredOutcome == "lose"):
|
|
return "rock"
|
|
return "paper"
|
|
|
|
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(throw, result):
|
|
return gameResult[result] + throws[throw]
|
|
|
|
for line in input:
|
|
opponentThrow = opponentThrowMap[line[0]]
|
|
myThrow = determineThrow(opponentThrow, desiredOutcomeMap[line[2]])
|
|
game = determineWinner(opponentThrow, myThrow)
|
|
total += calculateScore(myThrow, game)
|
|
|
|
print(total)
|
|
print(datetime.datetime.now()) |