about summary refs log tree commit diff
path: root/day23.k
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2015-12-23 17:20:42 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2015-12-23 17:20:42 +0100
commitd2958c5af4d86a0b8586e1dc461d390fcc313c40 (patch)
tree5f786a013becbf96c27727b3b13a652e76e06385 /day23.k
parent84e188fdc2972475b574785381e5f0982b26da8d (diff)
downloadadventofcode2015-d2958c5af4d86a0b8586e1dc461d390fcc313c40.tar.gz
adventofcode2015-d2958c5af4d86a0b8586e1dc461d390fcc313c40.tar.xz
adventofcode2015-d2958c5af4d86a0b8586e1dc461d390fcc313c40.zip
day23
Diffstat (limited to 'day23.k')
-rw-r--r--day23.k30
1 files changed, 30 insertions, 0 deletions
diff --git a/day23.k b/day23.k
new file mode 100644
index 0000000..7f6251d
--- /dev/null
+++ b/day23.k
@@ -0,0 +1,30 @@
+/ use k-3.2
+ss:{1 _' (&y=y,x) _ y,x}; / split x at y
+c:{ss[x@&~x=",";" "]}' 0:"day23";
+
+/ recursive
+run:{:[~x<#c;:r`b];o:c[x;0]~;d:`$c[x;1];
+ :[o"hlf";r[d]%:2; o"tpl";r[d]*:3; o"inc";r[d]+:1; o"jmp";:run x+. c[x;1]
+   o"jie";:[0=r[d]!2;:run x+. c[x;2]]; o"jio";:[1=r[d];:run x+. c[x;2]]]
+ run x+1}
+
+r[`a`b]:0 0
+run[0]
+
+r[`a`b]:1 0
+run[0]
+
+/ iteration
+run2:{o:(f:c x)[0]~;d:`$f 1;j:x+.:
+ :[o"hlf";r[d]%:2; o"tpl";r[d]*:3; o"inc";r[d]+:1
+   o"jmp";:j f 1; o"jie";:[0=r[d]!2;:j f 2]; o"jio";:[1=r[d];:j f 2]]
+ x+1}\[{x<#c};]
+
+r[`a`b]:0 0
+run2[0];
+r`b
+
+r[`a`b]:1 0
+run2[0];
+r`b
+