53 lines
1.1 KiB
Plaintext
53 lines
1.1 KiB
Plaintext
|
) get "input.ivy"
|
||
|
|
||
|
sample = 13 3 rho 2 2 2 1 2 2 3 2 2 2 1 2 2 3 2 2 2 1 2 2 3 2 2 4 2 2 6 1 2 5 3 2 5 2 1 5 2 3 5
|
||
|
#input = sample
|
||
|
|
||
|
) origin 0
|
||
|
|
||
|
op makeGrid coords =
|
||
|
lo = min/ transp coords
|
||
|
hi = max/ transp coords
|
||
|
coords = 1 1 1 + coords - lo
|
||
|
dim = 2 + (1 + hi - lo)
|
||
|
g = ,dim rho 0
|
||
|
g[dim decode transp coords] = 1
|
||
|
dim rho g
|
||
|
|
||
|
op makeBorder dim =
|
||
|
g = (dim-2) rho 0
|
||
|
g = 1,(2 0 1 transp g),1
|
||
|
g = 1,(2 0 1 transp g),1
|
||
|
g = 1,(2 0 1 transp g),1
|
||
|
g
|
||
|
|
||
|
op n twist a = 1 0 2 transp n flip (1 0 2 transp a)
|
||
|
|
||
|
op grow a = (1 rot a) or (-1 rot a) or (1 flip a) or (-1 flip a) or (1 twist a) or (-1 twist a)
|
||
|
op sides a = (1 rot a) + (-1 rot a) + (1 flip a) + (-1 flip a) + (1 twist a) + (-1 twist a)
|
||
|
|
||
|
lava = makeGrid input
|
||
|
|
||
|
"npoints = "; +/ ,lava
|
||
|
#lava
|
||
|
|
||
|
#border = makeBorder rho lava
|
||
|
#or/, lava and border # should == 0
|
||
|
|
||
|
op a flood walls =
|
||
|
x = grow a
|
||
|
b = (a or x) and not walls
|
||
|
and/, a == b: a
|
||
|
b flood walls
|
||
|
|
||
|
op solve2 lava =
|
||
|
water = (makeBorder rho lava) flood lava
|
||
|
+/, lava * sides water
|
||
|
|
||
|
op solve1 lava =
|
||
|
air = not lava
|
||
|
+/, lava * sides air
|
||
|
|
||
|
"part 1 ="; solve1 lava
|
||
|
"part 2 ="; solve2 lava
|