about summary refs log tree commit diff
path: root/day19.k
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2015-12-19 19:20:38 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2015-12-19 19:20:38 +0100
commitbff8b596a3a6ff4b363801fa058f1f35bc328ecf (patch)
tree444355a96b9177b9b18fe269bc15658d8553549a /day19.k
parent16625179ec285a8d5c70b459e29fd8d2c33771f9 (diff)
downloadadventofcode2015-bff8b596a3a6ff4b363801fa058f1f35bc328ecf.tar.gz
adventofcode2015-bff8b596a3a6ff4b363801fa058f1f35bc328ecf.tar.xz
adventofcode2015-bff8b596a3a6ff4b363801fa058f1f35bc328ecf.zip
day19
Diffstat (limited to 'day19.k')
-rw-r--r--day19.k14
1 files changed, 14 insertions, 0 deletions
diff --git a/day19.k b/day19.k
new file mode 100644
index 0000000..4626560
--- /dev/null
+++ b/day19.k
@@ -0,0 +1,14 @@
+/ use k-3.2
+ss:{1 _' (&y=y,x) _ y,x}; / split x at y
+l:{ss[x;" "]@0 2}' -2 _ 0:"day19";
+s:*|0:"day19";
+
+ssall:{[x;y;z]{[n](n#x),z,(n+#y) _ x}' x _ss y} / all substitutions
+
+#?,/{ssall[s;x@0;x@1]}'l / part 1
+
+step1:{[s],/{ssall[s;x@1;x@0]}'l}
+lim:{:[100<#x;100#x;x]}
+c:0
+{c+:1;r:?,/step1'x;lim@r@<#:'r}/[#:;,s];
+c-1 / part 2