63 lines
1.3 KiB
Python
63 lines
1.3 KiB
Python
from aocd.models import Puzzle
|
|
from aocd import submit
|
|
|
|
# score map part a
|
|
scores_a = {
|
|
"A X": 4,
|
|
"A Y": 8,
|
|
"A Z": 3,
|
|
"B X": 1,
|
|
"B Y": 5,
|
|
"B Z": 9,
|
|
"C X": 7,
|
|
"C Y": 2,
|
|
"C Z": 6,
|
|
}
|
|
|
|
# score map part b
|
|
scores_b = {
|
|
"A X": 3,
|
|
"A Y": 4,
|
|
"A Z": 8,
|
|
"B X": 1,
|
|
"B Y": 5,
|
|
"B Z": 9,
|
|
"C X": 2,
|
|
"C Y": 6,
|
|
"C Z": 7,
|
|
}
|
|
|
|
|
|
def eval_score(game: list, scores: dict) -> int:
|
|
"""
|
|
calculate the score of a game
|
|
"""
|
|
# map the move list to scores
|
|
score = [scores[move] for move in game]
|
|
# return the sum of all scores
|
|
return sum(score)
|
|
|
|
|
|
def parse_input(data: list) -> list:
|
|
"""
|
|
parses the input data and generates a list of elfs
|
|
"""
|
|
# split move set into a list of rounds
|
|
return [move for move in data.split("\n")]
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# get puzzle and parse data
|
|
puzzle = Puzzle(year=2022, day=2)
|
|
game = parse_input(puzzle.input_data)
|
|
|
|
# part a: calculate total score
|
|
total = eval_score(game, scores_a)
|
|
print(f"total points part a: {total}")
|
|
submit(total, part="a", day=2, year=2022)
|
|
|
|
# part b: calculate total score using the secret list
|
|
total = eval_score(game, scores_b)
|
|
print(f"total points part b: {total}")
|
|
submit(total, part="b", day=2, year=2022)
|