advent-of-code/2022/python/day02_golf.py

41 lines
503 B
Python
Raw Permalink Normal View History

2022-12-09 16:43:00 +00:00
import shared
R = "A"
P = "B"
S = "C"
2022-12-12 07:41:14 +00:00
X = "X" # lose
Y = "Y" # tie
Z = "Z" # win
2022-12-09 16:43:00 +00:00
Moves = {
2022-12-12 07:41:14 +00:00
R: {X: S, Y: R, Z: P},
P: {X: R, Y: P, Z: S},
S: {X: P, Y: S, Z: R},
2022-12-09 16:43:00 +00:00
}
Scores = {
2022-12-12 07:41:14 +00:00
R: 1,
P: 2,
S: 3,
X: 0,
Y: 3,
Z: 6,
2022-12-09 16:43:00 +00:00
}
2022-12-12 07:41:14 +00:00
2022-12-09 16:43:00 +00:00
def run(moves):
score = 0
for o, a in moves:
score += Scores[Moves[o][a]] + Scores[a]
print(score)
2022-12-12 07:41:14 +00:00
2022-12-09 16:43:00 +00:00
def main():
rows = [row.rstrip().split() for row in shared.load(2)]
run(rows)
if __name__ == "__main__":
main()