about summary refs log tree commit diff
path: root/day9.k
blob: 4ae90d15e4d5eb2488c2b3628f8fb77bb469009f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
d:0:"day9";

ss:{1 _' (&y=y,x) _ y,x}; / split x at y
l:ss[;" "]' d;

perm: {:[1<x;,/(>:'(x,x)#1,x#0)[;0,'1+_f x-1];,!x]};

dist:[];
{.[`dist;`$x[0 2];:; 0$x[4]]
 .[`dist;`$x[2 0];:; 0$x[4]]
}'l;

places: !dist;

ds:{+/dist':x}'places@perm@#places;

&/ds / shortest route
|/ds / longest route