-
Notifications
You must be signed in to change notification settings - Fork 1
/
16_The_Floor_Will_Be_Lava.py
47 lines (38 loc) · 1.2 KB
/
16_The_Floor_Will_Be_Lava.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
from aoc import *
map = Field(read())
def near(cur: Walker2d):
if cur.pos not in map:
return
match map[cur.pos]:
case ".":
yield cur.step()
case "|" if cur.dir.x:
yield cur.rotatelr("L").step()
yield cur.rotatelr("R").step()
case "|":
yield cur.step()
case "-" if cur.dir.y:
yield cur.rotatelr("L").step()
yield cur.rotatelr("R").step()
case "-":
yield cur.step()
case "/" if cur.dir.x:
yield cur.rotatelr("L").step()
case "/":
yield cur.rotatelr("R").step()
case "\\" if cur.dir.x:
yield cur.rotatelr("R").step()
case "\\":
yield cur.rotatelr("L").step()
case _:
raise cur
v = set(x.pos for x, d in bfs(Walker2d(dir=Vec2(1, 0)), near) if x.pos in map)
print(len(v))
dir = Vec2(0, 1)
max_energy = 0
for border in [map.row(0), map.column(map.w - 1), map.row(map.h - 1), map.column(0)]:
for start in border:
e = set(x.pos for x, _ in bfs(Walker2d(start, dir), near) if x.pos in map)
max_energy = max(max_energy, len(e))
dir = dir.rotatelr("R")
print(max_energy)