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

33 lines
811 B
Python

def do_task(lines):
card_score = []
for line in lines:
[wins, card] = line.split(": ")[1].split(" | ")
wins_set = set(wins.split())
card_set = set(card.split())
inter = wins_set.intersection(card_set)
card_score.append(len(inter))
card_score.reverse()
for i,s in enumerate(card_score):
card_score[i] = sum(card_score[(i-s):i]) + 1
return sum(card_score)
with open("day04/data/input100.txt") as infile:
lines = infile.readlines()
result = do_task(lines)
print(result)
print(result == 30)
with open("day04/data/input101.txt") as infile:
lines = infile.readlines()
result = do_task(lines)
print(result)
print(result == 5095824)