2022 day 2

This commit is contained in:
2022-12-02 18:52:42 +00:00
parent 2c9c2248ab
commit 3ccc8b3ebf
3 changed files with 2599 additions and 0 deletions

2500
2022/02/input Normal file

File diff suppressed because it is too large Load Diff

33
2022/02/part1 Executable file
View File

@@ -0,0 +1,33 @@
#!/usr/bin/env python
# lose: 0
# draw: 3
# win: 6
outcomes = {
'A': { # rock: 1
'X': 1 + 3, # rock
'Y': 2 + 6, # paper
'Z': 3 + 0 # scissors
},
'B': { # paper: 2
'X': 1 + 0, # rock
'Y': 2 + 3, # paper
'Z': 3 + 6 # scissors
},
'C': { # scissors: 3
'X': 1 + 6, # rock
'Y': 2 + 0, # paper
'Z': 3 + 3 # scissors
}
}
score = 0
with open('input') as f:
for line in f:
moves = line.rstrip().split(" ")
score = score + outcomes[moves[0]][moves[1]]
print(score)

66
2022/02/part2 Executable file
View File

@@ -0,0 +1,66 @@
#!/usr/bin/env python
# lose: 0
# draw: 3
# win: 6
# x: need to lose
# y: need to draw
# z: need to win
ROCK = 'A'
PAPER = 'B'
SCISSORS = 'C'
LOSE = 'X'
DRAW = 'Y'
WIN = 'Z'
outcomes = {
ROCK: { # rock: 1
ROCK: 1 + 3, # rock
PAPER: 2 + 6, # paper
SCISSORS: 3 + 0 # scissors
},
PAPER: { # paper: 2
ROCK: 1 + 0, # rock
PAPER: 2 + 3, # paper
SCISSORS: 3 + 6 # scissors
},
SCISSORS: { # scissors: 3
ROCK: 1 + 6, # rock
PAPER: 2 + 0, # paper
SCISSORS: 3 + 3 # scissors
}
}
strategies = {
ROCK: {
LOSE: SCISSORS,
DRAW: ROCK,
WIN: PAPER
},
PAPER: {
LOSE: ROCK,
DRAW: PAPER,
WIN: SCISSORS
},
SCISSORS: {
LOSE: PAPER,
DRAW: SCISSORS,
WIN: ROCK
}
}
score = 0
with open('input') as f:
for line in f:
parts = line.rstrip().split(" ")
oppo_move = parts[0]
our_move = strategies[oppo_move][parts[1]]
score = score + outcomes[oppo_move][our_move]
print(score)