import numpy as np import re, sys filename = open(sys.argv[1],"r") x = [] xr = filename.readlines()[0].strip() #print(filename.readline().rstrip()) #for i in filename.readlines(): # print (i.strip()) llist=[] bingo_numbers=[] with open(sys.argv[1]) as f: # x = [ j for j in x.split() ] #lines = f.readlines() #lines = [line.rstrip() for line in lines] for line in f: if re.search("^[0-9]+,",line.rstrip()): bingo_numbers = [int(i) for i in line.rstrip().split(',')] else: for x in line.rstrip().split(' '): if x != '': llist.append(x) plates = len(llist)/25 numbers=np.zeros((int(plates),5,5)) bingo=np.zeros((int(plates),5,5)) for l in range(0,int(plates)): for i in range(0,5): for j in range(0,5): numbers[l][i][j]=llist[0] llist.pop(0) #print() #print() print("----") print(bingo_numbers) force_break = False called_numbers = [] winner = [] already_called = [] for k in range(0,len(bingo_numbers)): for l in range(0,int(plates)): if l not in already_called: print('-----') print (l) print (already_called) print('>><<') if len(already_called) == int(plates)-1: force_break = True print('LAST IS NR ' + str(l)) called_numbers.append(bingo_numbers[0]) bingo_numbers.pop(0) break for i in range(0,5): for j in range(0,5): if numbers[l][i][j] == bingo_numbers[0]: bingo[l][i][j] = 1 if sum(bingo[l][i]) == 5: winner = numbers[l] already_called.append(l) #print(numbers[l]) #force_break = True #break if force_break: break print(called_numbers) print(winner) winner_sum = 0 for i in winner: for j in i: if int(j) not in called_numbers: winner_sum += int(j) print(winner_sum*called_numbers[-1])