24 lines
540 B
Python
24 lines
540 B
Python
#!/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)))
|