You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

82 lines
1.5 KiB

import aoclib
inp = aoclib.get_input(2, parser=aoclib.parse_lines_with_type_and_default(
typ=lambda l: l.split(" "), default=None))
def shape_value(us):
match us:
case "X":
return 1
case "Y":
return 2
case "Z":
return 3
def win_value(them, us):
win = 6
draw = 3
lose = 0
if them == "A":
match us:
case "X":
return draw
case "Y":
return win
case "Z":
return lose
elif them == "B":
match us:
case "X":
return lose
case "Y":
return draw
case "Z":
return win
else:
match us:
case "X":
return win
case "Y":
return lose
case "Z":
return draw
def get_round_value(them, us):
return shape_value(us) + win_value(them, us)
def map_part2(them, us):
mapping = {
"X": {
"A": "Z",
"B": "X",
"C": "Y"
},
"Y": {
"A": "X",
"B": "Y",
"C": "Z"
},
"Z": {
"A": "Y",
"B": "Z",
"C": "X"
}
}
us = mapping[us][them]
return get_round_value(them, us)
def part1():
return sum([get_round_value(them, us) for them, us in inp])
def part2():
return sum([map_part2(them, us) for them, us in inp])
aoclib.main(part1, part2)