-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_25.py
51 lines (36 loc) · 1.1 KB
/
day_25.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
43
44
45
46
47
48
49
50
51
from itertools import product
import aoc_helper
raw = aoc_helper.fetch(25, 2024)
def parse_raw(raw: str):
schemas = []
for scheme in raw.split("\n\n"):
a = scheme.strip().splitlines()
assert len(a) == 7
if set(a[0]) == {"#"}:
# it is a lock
hs = [0]*5
for x in range(5):
for y in range(7):
if a[y][x] == '#': hs[x] = y
schemas.append((0, tuple(hs)))
else:
# it is a key
hs = [0]*5
b = a[::-1]
for x in range(5):
for y in range(7):
if b[y][x] == '#': hs[x] = y
schemas.append((1, tuple(hs)))
return schemas
data = parse_raw(raw)
def part_one(data=data):
sepa = [[],[]]
for typ, x in data:
sepa[typ].append(x)
c = 0
for l, r in product(*sepa):
a = [i+j for i,j in zip(l,r)]
c += max(a) <= 5
return c
aoc_helper.lazy_test(day=25, year=2024, parse=parse_raw, solution=part_one)
aoc_helper.lazy_submit(day=25, year=2024, solution=part_one, data=data)