-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4b.py
42 lines (29 loc) · 756 Bytes
/
4b.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import numpy as np
data = open('input.txt').read().split('\n\n')
draw = [ int(d) for d in data[0].split(',') ]
def pipo(s):
return list(map(int, s.split()))
cards = [ np.array(list(map(pipo, d.splitlines()))) for d in data[1:] ]
def bingo(d):
global cards
to_be_removed = []
for i in range(len(cards)):
c = cards[i]
c[c == d] = -1
for row in c:
if np.sum(row) == -5:
to_be_removed.append(i)
continue
for column in c.T:
if np.sum(column) == -5:
to_be_removed.append(i)
continue
cards = np.delete(cards, to_be_removed, axis=0)
return len(cards) < 1
for d in draw:
c = cards[0]
b = bingo(d)
if b:
c[c == -1] = 0
print(d * sum(c.flatten()))
break