You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.7 KiB
60 lines
1.7 KiB
3 years ago
|
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):
|
||
|
rv = set()
|
||
|
for i in range(len(cards)):
|
||
|
counter = 0
|
||
|
for x in cards[i]:
|
||
|
# print(x)
|
||
|
if x[0] is None and x[1] is None and x[2] is None and x[3] is None and x[4] is None:
|
||
|
rv.add(i)
|
||
|
for t in range(5):
|
||
|
counter = 0
|
||
|
for x in cards[i]:
|
||
|
if x[t] is None:
|
||
|
counter += 1
|
||
|
if counter == 5:
|
||
|
rv.add(i)
|
||
|
return list(rv)
|
||
|
|
||
|
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 len(bing) > 0 and len(cards) > 1:
|
||
|
print('Found bingo: ', bing, ' after pulling number ', z, ', cards left: ', len(cards))
|
||
|
for card in reversed(sorted(bing)):
|
||
|
cards.pop(card)
|
||
|
continue
|
||
|
if len(cards) == 1 and len(bing) > 0:
|
||
|
for x in cards[0]:
|
||
|
for i in x:
|
||
|
if i is not None:
|
||
|
score += i
|
||
|
break
|
||
|
print(cards)
|
||
|
print(z)
|
||
|
print(score*z, ' eöokrggm')
|