This commit is contained in:
Sebastian Seedorf
2020-12-29 17:26:41 +01:00
parent 259eb24308
commit 9e79644296
3 changed files with 111 additions and 0 deletions

23
day22/part1.py Normal file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env python3
lines = (x.strip() for x in open("input.txt"))
stats = [[], []]
player2 = False
for line in lines:
if line.startswith("Player"):
continue
elif line == "":
player2 = True
else:
stats[1 if player2 else 0].append(int(line))
while all(len(x) > 0 for x in stats):
a, b = stats[0].pop(0), stats[1].pop(0)
if a > b:
stats[0].extend((a, b))
else:
stats[1].extend((b, a))
print(list(map(lambda x: sum(i*v for i, v in zip(x, range(len(x), 0, -1))), stats)))