#!/usr/bin/env python3 import queue with open("data/input.txt", "r") as f: data = f.read() q = queue.Queue() def winning_copies(card): lists = card.split(":")[1].split("|") winning = lists[0].split() numbers = lists[1].split() matching = 0 for number in numbers: if number in winning: matching += 1 return matching cards = data.split("\n") cards.remove("") for i, card in enumerate(cards): q.put((i, card)) counter = 0 while not q.empty(): i, card = q.get() copies = winning_copies(card) if copies > 0: for j in range(1, copies+1): copy = cards[i+j] q.put((i+j, copy)) counter += 1 print(counter)