aboutsummaryrefslogtreecommitdiff
path: root/day6.k
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2015-12-06 20:17:19 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2015-12-06 20:17:19 +0100
commitbe8000bb4e4ec9f32efc71a32990968827f64e9e (patch)
tree6f594762c34ac0b5dbd2c0572a1a55e9fa73c4e6 /day6.k
parent62733cd7efbc99a5f99b8ce007fa8c2e31c74d2c (diff)
downloadadventofcode2015-be8000bb4e4ec9f32efc71a32990968827f64e9e.tar.gz
adventofcode2015-be8000bb4e4ec9f32efc71a32990968827f64e9e.tar.xz
adventofcode2015-be8000bb4e4ec9f32efc71a32990968827f64e9e.zip
day6
Diffstat (limited to 'day6.k')
-rw-r--r--day6.k36
1 files changed, 36 insertions, 0 deletions
diff --git a/day6.k b/day6.k
new file mode 100644
index 0000000..6f95738
--- /dev/null
+++ b/day6.k
@@ -0,0 +1,36 @@
+d:0:"day6";
+
+ss:{1 _' (&y=y,x) _ y,x}; / split x at y
+ds:{0$ss[x;","]}; / split , digits
+rg:{(x&y)+!(_abs x - y)+1}; / range x..y inclusive
+
+l:ss[;" "]' d;
+
+f:1000 1000 # 0;
+
+on: {f[rg[x[0];x[2]];rg[x[1];x[3]]]:1};
+off: {f[rg[x[0];x[2]];rg[x[1];x[3]]]:0};
+toggle:{f[rg[x[0];x[2]];rg[x[1];x[3]]]~:};
+
+op:{
+ :["on"~x[1];on[,/ds'x[2 4]]
+ "off"~x[1];off[,/ds'x[2 4]]
+ "toggle"~x[0];toggle[,/ds'x[1 3]]]
+};
+
+op' l;
+
+#&,/f
+
+/ 2nd part
+
+f:1000 1000 # 0;
+
+on: {f[rg[x[0];x[2]];rg[x[1];x[3]]]+:1};
+off: {f[rg[x[0];x[2]];rg[x[1];x[3]]]-:1
+ f[rg[x[0];x[2]];rg[x[1];x[3]]]|:0};
+toggle:{f[rg[x[0];x[2]];rg[x[1];x[3]]]+:2};
+
+op' l;
+
++/+/f