about summary refs log tree commit diff
path: root/day9.k
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2015-12-09 14:17:12 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2015-12-09 14:17:12 +0100
commit4af2965c747210abb8ca2a405b45bcd1e513074e (patch)
tree269fd7dabac2bae716adc193e684292a01f07c93 /day9.k
parent3f63cb8a2d53fd33ce800ca6944a92af0c6b1b24 (diff)
downloadadventofcode2015-4af2965c747210abb8ca2a405b45bcd1e513074e.tar.gz
adventofcode2015-4af2965c747210abb8ca2a405b45bcd1e513074e.tar.xz
adventofcode2015-4af2965c747210abb8ca2a405b45bcd1e513074e.zip
day9
Diffstat (limited to 'day9.k')
-rw-r--r--day9.k18
1 files changed, 18 insertions, 0 deletions
diff --git a/day9.k b/day9.k
new file mode 100644
index 0000000..4ae90d1
--- /dev/null
+++ b/day9.k
@@ -0,0 +1,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