-
Notifications
You must be signed in to change notification settings - Fork 139
Advent of Corona
Tom Szczesny edited this page May 8, 2020
·
67 revisions
https://adventofcorona.hackersatupc.org
Problem 1, Phase 1
f: { a:~0,(1 _ x)>(-1 _ x); b:~1,((1 _ x)-(-1 _ x))!2; c:&(a|b),1; |/(1 _ c)-(-1 _ c) }
f(. (0: "/home/tom/corona/input1") 0)
Problem 1, Phase 2
f: { a: x[<x]; b: a[&((1 _ a)>(-1 _ a)),1]; ^b[&((1 _ b)-(-1 _ b)),1] }
f(. (0: "/home/tom/corona/input1") 0)
Problem 2, Phase 1
f: { a:(0 0 1 0;0 1 0 0;1 0 0 0); b:(3 4#x)-a; b[&~-1 _in' b[;!3]] }
s: { x:x[<x]; i:,/1#'=x[;!3]; x[i;3]:+/'x[=x[;!3];3]; x[i] }
r: { do[30; x:s[,/f'x]]; x }
r[,10 10 10 1] 0 3
Problem 2, Phase 2
f: { a:(0 0 0 0 1 0 0;0 0 0 1 0 0 0;0 0 1 0 0 0 0;0 1 0 0 0 0 0;1 0 0 0 0 0 0)
b:(5 7#x)-a; b[&~-1 _in' b[;!5]] }
j: { x[;5]: x[;5]+ _ x[;6]%1000000000; x[;6]: x[;6] ! 1000000000; x }
s: { x:j[x[<x]]; i:,/1#'=x[;!5]; x[i;5 6]:+/'x[=x[;!5];5 6]; x[i] }
r: { do[25; x:s[,/f'x]]; x }
. ,/ $ r[,5 5 5 5 5 0 1][0;5 6]
Problem 3, Phase 1
i: &"I"= m: ,/ 1 _ -1 _ 0: "/home/tom/corona/input3a"
m[i[&i>99]-100]:"X"; m[i[&i<9900]+100]:"X";
m[i[&(i!100)> 0]-1]:"X"; m[i[&(i!100)<99]+1]:"X"; m:100 100#m;
d:100 100 # 0; deltas:(-1 0;1 0;0 -1;0 1); q:,12 42;
while[ 0<#q;
curr:q[0]; q:1 _ q; dist:d[curr[0];curr[1]]; val:m[curr[0];curr[1]];
if[ val="C"; \ dist ]; i:0;
do[ 4; n:curr+deltas[i]; i+:1;
if[ (n[0]>-1) & (n[0]<100) & (n[1]>-1) & (n[1]<100);
if[ (~m[n[0];n[1]]="X") & (d[n[0];n[1]]=0);
d[n[0];n[1]]:dist+1; q:q,,n; ] ] ] ]
Problem 3, Phase 2
i: &"I"= m: ,/ 1 _ -1 _ 0: "/home/tom/corona/input3b"
m[i[&i>99]-100]:"X"; m[i[&i<9900]+100]:"X";
m[i[&(i!100)> 0]-1]:"X"; m[i[&(i!100)<99]+1]:"X"; m:100 100#m;
d:100 100 # 0; jumps:(-3 0;3 0;0 -3;0 3); q:,43 32;
while[ 0<#q;
curr:q[0]; q:1 _ q; dist:d[curr[0];curr[1]]; val:m[curr[0];curr[1]];
if[ val="H"; \ dist ];
deltas:(-1 0;1 0;0 -1;0 1),jumps[&"DULR"=val]; i:0;
do[ #deltas; n:curr+deltas[i]; i+:1;
if[ (n[0]>-1) & (n[0]<100) & (n[1]>-1) & (n[1]<100);
if[ (~m[n[0];n[1]]="X") & (d[n[0];n[1]]=0);
d[n[0];n[1]]:dist+1; q:q,,n; ] ] ] ]
Problem 4
Cipher Text
VVVQBRCAAQKACMASCUI,KMAWAMOCYI
Key
CORONAONAISNOTAJOKESTAYATHOME
Problem 5a
n: . (1 _ 0: "/home/tom/corona/input4")[0]
v: (-1 _ ~(n,101)>101,n) & 1 _ ~(101,n)>n,101
i: (-1+&v),1+&v; j:i[&v[i]=0]; v[j]:2;
v[& (-1 _ 0,v=2) & v=0]:3; v[& (1 _ (v=2),0) & v=0]:3;
v[-1 + & (v=3) & (-1!2=v) & n<-1!n]:4
v[ 1 + & (v=3) & ( 1!2=v) & n< 1!n]:4; v[998 999]:4 5;
i: &v=0; v[i]:4; v[i[& n[i-1]>n[i]]-1]:5;
i: &v=0; j:i[&v[i-1]=3]; v[j]:4; v[&v=0]:5;
j: & (3=v) & 3=1!v;
i: j[& n[j+1]<n[j]]; v[i]:4;
i: j[& n[j+1]>n[j]]; v[i+1]:4;
v[ 1 + & (v=4) & ( 1!3=v) & n< 1!n]:5
i: j[& n[j+2]>n[j+1]]; v[i+2]:5;
i: j[& n[j-1]>n[j]]; v[i-1]:5;
v[ 1 + & (v=5) & ( 1!4=v) & n<1!n ]:6
i: &(2=v) & 2=1!v; j:i[&n[i]>n[i+1]]; v[j]:3; j:i[&n[i]<n[i+1]]; v[j+1]:3;
+/v
Problem 5b
n: . (1 _ 0: "/home/tom/corona/input4")[0]
v: (-1 _ ~(n,101)>101,n) & 1 _ ~(101,n)>n,101
i: (-1+&v),1+&v; j:i[&v[i]=0]; v[j]:2;
v[& (-1 _ 0,v=2) & v=0]:3; v[& (1 _ (v=2),0) & v=0]:3;
v[-1 + & (v=3) & (-1!2=v) & n<-1!n]:4
v[ 1 + & (v=3) & ( 1!2=v) & n< 1!n]:4; v[998 999]:4 5;
i: &v=0; v[i]:4; v[i[& n[i-1]>n[i]]-1]:5;
i: &v=0; j:i[&v[i-1]=3]; v[j]:4; v[&v=0]:5;
j: & (3=v) & 3=1!v;
i: j[& n[j+1]<n[j]]; v[i]:4;
i: j[& n[j+1]>n[j]]; v[i+1]:4;
v[ 1 + & (v=4) & ( 1!3=v) & n< 1!n]:5
i: j[& n[j+2]>n[j+1]]; v[i+2]:5;
i: j[& n[j-1]>n[j]]; v[i-1]:5;
v[ 1 + & (v=5) & ( 1!4=v) & n<1!n ]:6
i: &(2=v) & 2=1!v; j:i[&n[i]>n[i+1]]; v[j]:3; j:i[&n[i]<n[i+1]]; v[j+1]:3;
(-2 _ "[",/($v),\:", "),"]"
Problem 13
s:343#0; s[0 1]:1 2; v:1 1; i:2;
while[ i<#s
v:((v,0)+0,v)!10000000000004;
s[i]:+/0<v!7; i+:1; ]
do[ 6; s:s,(2*s),(3*s),(4*s),(5*s),(6*s),(7*s) ]
s:s,(2*s),(3*s),(4*s)
+/s[!133701337]
Problem 14a
s: * 0: "/home/tom/corona/input14a"
ss:#s; c:0; k:1;
while[ k<ss-1
i:0; j:ss-k; jj:!j;
while[ i<(ss+2)-((ss+1)-k)
t:s[i+jj]
if[ ((*t)=*|t)
c:c+1
/ \ (,/($c,i,j),'" "),t
if[ 2<#t
n:2
while[ n<#t
if[ (&/(n#t)=|n#t) & &/(n#t)=n#|t
c:c+1
/ \ (,/($c,i,j),'" "),t," ",t[!n]
]
n:n+1 ] ] ]
i:i+1 ]
\ k,c; k:k+1; ]
Problem 14b
s: * 0: "/home/tom/corona/input14b"
ss:#s; c:0; d:0; k: 1;
while[ k<ss-1
if[ c>1000000007
d:d+1; c:c!1000000007; ]
\ k,d,c
i:0; j:ss-k; jj:!j;
while[ i<(ss+2)-((ss+1)-k)
t:s[i+jj]
if[ ((*t)=*|t)
c:c+1
if[ 2<#t
n:2
w: 1 + *& ~t= |t
if[ w=1; w:#t ]
while[ n<w
if[ (&/(n#t)=|n#t) & &/(n#t)=n#|t
c:c+1 ]
n:n+1 ] ] ]
i:i+1 ]
\ k,d,c; k:k+1; ]