-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04.py
42 lines (32 loc) · 1.01 KB
/
04.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
from lib import *
input = read_input(2021, 4)
nums, *boards = input.split("\n\n")
nums = ints(nums)
boards = [[[*map(int, line.split())] for line in b.splitlines()] for b in boards]
marked = set()
for num in nums:
marked.add(num)
for b in boards:
if any(all(x in marked for x in row) for row in b) or any(all(x in marked for x in col) for col in zip(*b)):
score = num * sum(x for row in b for x in row if x not in marked)
print(score)
break
else:
continue
break
won = set()
marked = set()
for num in nums:
marked.add(num)
for i, b in enumerate(boards):
if i in won:
continue
if any(all(x in marked for x in row) for row in b) or any(all(x in marked for x in col) for col in zip(*b)):
won.add(i)
if len(won) == len(boards):
score = num * sum(x for row in b for x in row if x not in marked)
print(score)
break
else:
continue
break