adventofcode2022/day23/sol.ivy

65 lines
1.4 KiB
XML

)get "input.ivy"
sample = 7 7 rho '....#..' '..###.#' '#...#.#' '.#...##' '#.###..' '##.#.##' '.#..#..'
board = sample == '#'
#board
op north a = 1 flip a
op south a = -1 flip a
op west a = 1 rot a
op east a = -1 rot a
#north 3 3 rho iota 9
op a coalesce b =
a: a
b
op any a = or/,a
op pad a = 0,(transp (0,(transp a),0)),0
op needsPad a = (any 0 != a[1,(rho a)[1]]) or (any 0 != a[;(1,(rho a)[2])])
op maybePad a =
needsPad a: pad a
a
op smearWE a = a or (west a) or (east a)
op smearNS a = a or (north a) or (south a)
op lift a = (1,rho a) rho a
op show a = (text ".#23456789"[1+a]),"\n-"
M = 0
a = maybePad board
n = south smearWE a
s = north smearWE a
e = west smearNS a
w = east smearNS a
#n
p = 4 3 2 1
C = (lift n) , (lift s) , (lift w) , (lift e)
rho C
canMove = a and or/ 3 1 2 transp C # can move if there is an elf nearby
C2 = (not C) and (rho C) rho canMove # can move in a direction if not alone and there is no elf in that direction
show C2
P1 = max/ p * 3 1 2 transp C2 # select direction
P2 = p o.== P1 # decompose into 4x?x? matrix
P1; "\n-"
C3 = (north P2[1]) + (south P2[2]) + (west P2[3]) + (east P2[4])
C3; "\n-"
notBlock = C3 == 1
C4 = (lift south notBlock), (lift north notBlock), (lift east notBlock), (lift west notBlock)
rho C4
P3 = P2 and C4
show P3
moved = or/ 3 1 2 transp P3
moved
#a and not moved
#show P3
B = (a and not moved) + (north P3[1]) + (south P3[2]) + (west P3[3]) + (east P3[4])
show a
show B