feat: part 1 of day 2 complete

This commit is contained in:
2022-12-02 23:03:02 -05:00
parent 9e4c19567a
commit 4d92ccc5a9
3 changed files with 2560 additions and 2 deletions

View File

@@ -1,5 +1,3 @@
import string
elves = [[]]

2500
day2/input.txt Normal file

File diff suppressed because it is too large Load Diff

60
day2/main.py Normal file
View File

@@ -0,0 +1,60 @@
rounds = []
input_file = open("input.txt", "r")
lines = input_file.readlines()
for line in lines:
moves = line.split(" ")
rounds.append([])
rounds[-1].append(moves[0])
rounds[-1].append(moves[1].replace("\n", ""))
move_score = {
"X": 1, # rock
"Y": 2, # paper
"Z": 3, # scissors
}
OPPONENT_ROCK = "A"
OPPONENT_PAPER = "B"
OPPONENT_SCISSORS = "C"
MY_ROCK = "X"
MY_PAPER = "Y"
MY_SCISSORS = "Z"
def opponent_did_win(opponent_move, my_move):
if opponent_move == OPPONENT_ROCK:
return my_move == MY_SCISSORS
elif opponent_move == OPPONENT_PAPER:
return my_move == MY_ROCK
elif opponent_move == OPPONENT_SCISSORS:
return my_move == MY_PAPER
def opponent_did_tie(opponent_move, my_move):
if opponent_move == OPPONENT_ROCK:
return my_move == MY_ROCK
elif opponent_move == OPPONENT_PAPER:
return my_move == MY_PAPER
elif opponent_move == OPPONENT_SCISSORS:
return my_move == MY_SCISSORS
total_score = 0
for _round in rounds:
opponent_move = _round[0]
my_move = _round[1]
# always add your move to the total score
total_score += move_score[my_move]
if opponent_did_tie(opponent_move, my_move):
total_score += 3
elif not opponent_did_win(opponent_move, my_move):
total_score += 6
print(total_score)