29 lines
710 B
Python
29 lines
710 B
Python
|
with open("input.txt") as f:
|
||
|
lines = f.readlines()
|
||
|
|
||
|
part1 = 0
|
||
|
|
||
|
for line in lines:
|
||
|
_, card = line.split(": ")
|
||
|
winning, yours = card.split(" | ")
|
||
|
winning = {int(n) for n in winning.split()}
|
||
|
yours = {int(n) for n in yours.split()}
|
||
|
how_many_wins = len(winning & yours)
|
||
|
worth = 2 ** (how_many_wins - 1) if how_many_wins >= 1 else 0
|
||
|
part1 += worth
|
||
|
|
||
|
print(part1)
|
||
|
|
||
|
cards = [1]*len(lines)
|
||
|
|
||
|
for i, line in enumerate(lines):
|
||
|
_, card = line.split(": ")
|
||
|
winning, yours = card.split(" | ")
|
||
|
winning = {int(n) for n in winning.split()}
|
||
|
yours = {int(n) for n in yours.split()}
|
||
|
how_many_wins = len(winning & yours)
|
||
|
for n in range(i+1, i+1+how_many_wins):
|
||
|
cards[n] += 1 * cards[i]
|
||
|
|
||
|
part2 = sum(cards)
|
||
|
print(part2)
|