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.

23 lines
499 B
Python

#!/usr/bin/env python3
"""Part1"""
import sys
RESULT = 0
for line in sys.stdin.readlines():
line = line.strip()
card_no, numbers = line.split(": ")
numbers_win, numbers_have = numbers.split(" | ")
numbers_win = set(numbers_win.split())
numbers_have = set(numbers_have.split())
matches = numbers_win & numbers_have
num_matches = len(matches)
worth = 2 ** (num_matches - 1)
worth = int(worth)
print(f"{card_no}: {worth}")
RESULT += worth
print(RESULT)