about summary refs log tree commit diff
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
parent84e188fdc2972475b574785381e5f0982b26da8d (diff)
downloadadventofcode2015-d2958c5af4d86a0b8586e1dc461d390fcc313c40.tar.gz
adventofcode2015-d2958c5af4d86a0b8586e1dc461d390fcc313c40.tar.xz
adventofcode2015-d2958c5af4d86a0b8586e1dc461d390fcc313c40.zip
day23
-rw-r--r--day2346
-rw-r--r--day23.k30
2 files changed, 76 insertions, 0 deletions
diff --git a/day23 b/day23
new file mode 100644
index 0000000..79d9624
--- /dev/null
+++ b/day23
@@ -0,0 +1,46 @@
+jio a, +16
+inc a
+inc a
+tpl a
+tpl a
+tpl a
+inc a
+inc a
+tpl a
+inc a
+inc a
+tpl a
+tpl a
+tpl a
+inc a
+jmp +23
+tpl a
+inc a
+inc a
+tpl a
+inc a
+inc a
+tpl a
+tpl a
+inc a
+inc a
+tpl a
+inc a
+tpl a
+inc a
+tpl a
+inc a
+inc a
+tpl a
+inc a
+tpl a
+tpl a
+inc a
+jio a, +8
+inc b
+jie a, +4
+tpl a
+inc a
+jmp +2
+hlf a
+jmp -7
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
+