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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
op pady a = -1, a, -1
|
|
|
|
op padx a = transp pady transp a
|
|
|
|
op pad a = pady padx a
|
|
|
|
|
|
|
|
A = pad sample
|
|
|
|
|
|
|
|
|
|
|
|
i = 3 3
|
|
|
|
d = 1 0
|
|
|
|
|
|
|
|
op i slice d =
|
|
|
|
t = A[i[1];i[2]]
|
|
|
|
t < 0: 0 rho 0
|
|
|
|
t, (i+d) slice d
|
|
|
|
|
|
|
|
A
|
|
|
|
A[3;3]
|
|
|
|
i slice d
|
|
|
|
i slice -d
|
|
|
|
|
|
|
|
op empty v = 0 == rho v
|
|
|
|
|
2022-12-10 05:22:18 +00:00
|
|
|
# takes from v while v[i] is less than x
|
|
|
|
op x shorter v =
|
2022-12-10 05:21:52 +00:00
|
|
|
empty v: v
|
|
|
|
(and\ x > v) sel v
|
|
|
|
|
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-10 05:22:18 +00:00
|
|
|
v = 1 2 3 4 3 2 5 6 1 2 3
|
2022-12-10 05:21:52 +00:00
|
|
|
|
2022-12-10 05:22:18 +00:00
|
|
|
5 shorter v
|
|
|
|
0 shorter 1 2 3
|
2022-12-10 05:21:52 +00:00
|
|
|
|
|
|
|
# takes from v while v[i] is less than v[0]
|
|
|
|
op shorter2 v =
|
|
|
|
x = v[1]
|
|
|
|
v = 1 flip v
|
|
|
|
v, +/ (and\ transp x > v)
|
|
|
|
|
|
|
|
#shorter2 transp (1, rho v) rho v
|
|
|
|
#shorter2 3 3 rho flip iota 9
|
|
|
|
|
|
|
|
""
|
|
|
|
sample
|
|
|
|
"-"
|
|
|
|
|
2022-12-10 05:22:18 +00:00
|
|
|
op x viewDistance v = (x blocked v) + rho x shorter v
|
|
|
|
op viewDistance v = v[1] viewDistance 1 drop v
|
2022-12-10 05:21:52 +00:00
|
|
|
|
|
|
|
viewDistance 1 2 3
|
|
|
|
viewDistance 5 1 2 3
|
|
|
|
viewDistance 5 5
|
|
|
|
|
|
|
|
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 =
|
|
|
|
i[2] > (rho A)[2]: 0
|
|
|
|
(i score A) max (i + 0 1) loopY A
|
|
|
|
|
|
|
|
op i loopX A =
|
|
|
|
i[1] > (rho A)[1]: 0
|
|
|
|
(i loopY A) max (i + 1 0) loopX A
|
|
|
|
|
2022-12-10 05:22:18 +00:00
|
|
|
op solve A = 1 1 loopX A
|
2022-12-10 05:21:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
1 1 score sample
|
|
|
|
2 2 score sample
|
|
|
|
3 4 score sample
|
2022-12-10 05:22:18 +00:00
|
|
|
solve sample
|
2022-12-10 05:21:52 +00:00
|
|
|
|
2022-12-10 05:22:18 +00:00
|
|
|
1 1 score sample; 1 2 score sample; 1 3 score sample; 1 4 score sample; 1 5 score sample
|
|
|
|
2 1 score sample; 2 2 score sample; 2 3 score sample; 2 4 score sample; 2 5 score sample
|
|
|
|
solve input
|