def do_task(lines): win_sum = 0 for line in lines: # print(line) [wins, card] = line.split(": ")[1].split(" | ") wins_set = set(wins.split()) card_set = set(card.split()) inter = wins_set.intersection(card_set) # print(inter) win_sum += 2 ** (len(inter) - 1) if len(inter) > 0 else 0 return win_sum with open("day04/data/input100.txt") as infile: lines = infile.readlines() result = do_task(lines) print(result) print(result == 13) with open("day04/data/input101.txt") as infile: lines = infile.readlines() result = do_task(lines) print(result) print(result == 22897)