import re def check(cards, num): for i in cards: for x in i: for t in range(5): if x[t] == num: x[t] = None print(cards) def bingo(cards): for i in cards: counter = 0 for x in i: if x[1] is None and x[2] is None and x[3] is None and x[4] is None and x[5] is None: return i for t in range(5): counter = 0 for x in i: if x[t] is None: counter += 1 if counter == 5: return i return None nums = [4,75,74,31,76,79,27,19,69,46,98,59,83,23,90,52,87,6,11,92,80,51,43,5,94,17,15,67,25,30,48,47,62,71,85,58,60,1,72,99,3,35,42,10,96,49,37,36,8,44,70,40,45,39,0,63,2,78,68,53,50,77,20,55,38,86,54,93,26,88,12,91,95,34,9,14,33,66,41,13,28,57,29,73,56,22,89,21,64,61,32,65,97,84,18,82,81,7,16,24] f = open('input4.txt', 'r') cards = [] card = [] score = 0 for i in f: i = i.strip() if len(i) == 0: cards.append(card) card = list() continue t = list(map(int, re.split('\s+', i))) card.append(t) if len(card) > 0: cards.append(card) for z in nums: check(cards, z) bing = bingo(cards) if bing is not None: print(bing) print(z) for x in bing: for i in x: if i is not None: score += i break print(score*z)