67 lines
1.1 KiB
XML
67 lines
1.1 KiB
XML
) get "input.ivy"
|
|
|
|
sample = 5 5 rho 3 0 3 7 3 2 5 5 1 2 6 5 3 3 2 3 3 5 4 9 3 5 3 9 0
|
|
|
|
########
|
|
"part 1"
|
|
|
|
op visible r =
|
|
r = -1, r
|
|
r = transp max\ transp r
|
|
r = r > -1 flip r
|
|
1 drop r
|
|
|
|
op vis2 m = (visible m) or (flip visible flip m)
|
|
op vis4 m = (vis2 m) or (transp vis2 transp m)
|
|
|
|
sample
|
|
+/, vis4 sample
|
|
+/, vis4 input
|
|
|
|
|
|
##########
|
|
"\npart 2"
|
|
|
|
op empty v = 0 == rho v
|
|
|
|
# count how many elements at the start of v are less than x
|
|
op x shorter v =
|
|
empty v: 0
|
|
+/ (and\ x > v)
|
|
|
|
# returns 1 if any v[i] blocks x
|
|
op x blocked v =
|
|
empty v: 0
|
|
or/ x <= v
|
|
|
|
op x viewDistance v = (x blocked v) + x shorter v
|
|
|
|
op p score A =
|
|
x = p[1]
|
|
y = p[2]
|
|
e = A[y;x]
|
|
row = A[y]
|
|
col = A[;x]
|
|
n = 1
|
|
n = n * e viewDistance flip (x-1) take row
|
|
n = n * e viewDistance x drop row
|
|
n = n * e viewDistance flip (y-1) take col
|
|
n = n * e viewDistance y drop col
|
|
n
|
|
|
|
op i loopY A =
|
|
x = i score A
|
|
i[2] >= (rho A)[2]: x
|
|
x , (i + 0 1) loopY A
|
|
|
|
op i loopX A =
|
|
x = i loopY A
|
|
i[1] >= (rho A)[1]: x
|
|
x , (i + 1 0) loopX A
|
|
|
|
op solve A = max/ 1 1 loopX A
|
|
|
|
sample
|
|
solve sample
|
|
solve input
|