2022-12-08 07:11:37 +00:00
|
|
|
) 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
|
|
|
|
|
2022-12-12 02:21:07 +00:00
|
|
|
########
|
|
|
|
"part 1"
|
|
|
|
|
2022-12-08 07:11:37 +00:00
|
|
|
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
|
|
|
|
|
2022-12-10 05:21:52 +00:00
|
|
|
|
2022-12-12 02:21:07 +00:00
|
|
|
##########
|
|
|
|
"\npart 2"
|
2022-12-10 05:21:52 +00:00
|
|
|
|
|
|
|
op empty v = 0 == rho v
|
|
|
|
|
2022-12-12 02:21:07 +00:00
|
|
|
# count how many elements at the start of v are less than x
|
2022-12-10 05:22:18 +00:00
|
|
|
op x shorter v =
|
2022-12-12 02:21:07 +00:00
|
|
|
empty v: 0
|
|
|
|
+/ (and\ x > v)
|
2022-12-10 05:21:52 +00:00
|
|
|
|
2022-12-10 05:22:18 +00:00
|
|
|
# returns 1 if any v[i] blocks x
|
|
|
|
op x blocked v =
|
2022-12-10 05:21:52 +00:00
|
|
|
empty v: 0
|
2022-12-10 05:22:18 +00:00
|
|
|
or/ x <= v
|
2022-12-10 05:21:52 +00:00
|
|
|
|
2022-12-12 02:21:07 +00:00
|
|
|
op x viewDistance v = (x blocked v) + x shorter v
|
2022-12-10 05:21:52 +00:00
|
|
|
|
|
|
|
op p score A =
|
|
|
|
x = p[1]
|
|
|
|
y = p[2]
|
|
|
|
e = A[y;x]
|
|
|
|
row = A[y]
|
|
|
|
col = A[;x]
|
|
|
|
n = 1
|
2022-12-10 05:22:18 +00:00
|
|
|
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
|
2022-12-10 05:21:52 +00:00
|
|
|
n
|
|
|
|
|
|
|
|
op i loopY A =
|
2022-12-12 02:21:07 +00:00
|
|
|
x = i score A
|
|
|
|
i[2] >= (rho A)[2]: x
|
|
|
|
x , (i + 0 1) loopY A
|
2022-12-10 05:21:52 +00:00
|
|
|
|
|
|
|
op i loopX A =
|
2022-12-12 02:21:07 +00:00
|
|
|
x = i loopY A
|
|
|
|
i[1] >= (rho A)[1]: x
|
|
|
|
x , (i + 1 0) loopX A
|
2022-12-10 05:21:52 +00:00
|
|
|
|
2022-12-12 02:21:07 +00:00
|
|
|
op solve A = max/ 1 1 loopX A
|
2022-12-10 05:21:52 +00:00
|
|
|
|
2022-12-12 02:21:07 +00:00
|
|
|
sample
|
2022-12-10 05:22:18 +00:00
|
|
|
solve sample
|
|
|
|
solve input
|