Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def day4(s, *, part2=False):
- copies = collections.Counter()
- total = 0
- for card_id, line in enumerate(s.splitlines()):
- winning, have = map(str.split, line.split(':')[1].split(' | '))
- num_matches = len(set(winning) & set(have))
- if part2:
- value = 1 + copies[card_id]
- for i in range(num_matches):
- copies[card_id + 1 + i] += value
- total += value
- elif num_matches:
- total += 2 ** (num_matches - 1)
- return total
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement