adventofcode/2022/day_2/part1.py

34 lines
468 B
Python
Raw Normal View History

2022-12-02 08:40:51 +00:00
ahand = ("A", "B", "C")
bhand = ("X", "Y", "Z")
win_tbl = (
("A", "Y"),
("B", "Z"),
("C", "X"),
)
def load(filename):
with open(filename) as f:
t = 0
for l in f:
a, b = l.rstrip().split(" ")
h = bhand.index(b) + 1
ai = ahand.index(a)
bi = bhand.index(b)
if ai == bi:
t += h + 3
elif (a, b) in win_tbl:
t += h + 6
else:
t += h
return t
assert load("demo.txt") == 15
t = load("data.txt")
print(f"You have {t} points.")