about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--day10139
-rw-r--r--day10.k3
-rw-r--r--day10.mew31
-rw-r--r--day10.rkt31
4 files changed, 204 insertions, 0 deletions
diff --git a/day10 b/day10
new file mode 100644
index 0000000..c26a664
--- /dev/null
+++ b/day10
@@ -0,0 +1,139 @@
+noop
+addx 12
+addx -5
+addx -1
+noop
+addx 4
+noop
+addx 1
+addx 4
+noop
+addx 13
+addx -8
+noop
+addx -19
+addx 24
+addx 1
+noop
+addx 4
+noop
+addx 1
+addx 5
+addx -1
+addx -37
+addx 16
+addx -13
+addx 18
+addx -11
+addx 2
+addx 23
+noop
+addx -18
+addx 9
+addx -8
+addx 2
+addx 5
+addx 2
+addx -21
+addx 26
+noop
+addx -15
+addx 20
+noop
+addx 3
+noop
+addx -38
+addx 3
+noop
+addx 26
+addx -4
+addx -19
+addx 3
+addx 1
+addx 5
+addx 3
+noop
+addx 2
+addx 3
+noop
+addx 2
+noop
+noop
+noop
+noop
+addx 5
+noop
+noop
+noop
+addx 3
+noop
+addx -30
+addx -4
+addx 1
+addx 18
+addx -8
+addx -4
+addx 2
+noop
+addx 7
+noop
+noop
+noop
+noop
+addx 5
+noop
+noop
+addx 5
+addx -2
+addx -20
+addx 27
+addx -20
+addx 25
+addx -2
+addx -35
+noop
+noop
+addx 4
+addx 3
+addx -2
+addx 5
+addx 2
+addx -11
+addx 1
+addx 13
+addx 2
+addx 5
+addx 6
+addx -1
+addx -2
+noop
+addx 7
+addx -2
+addx 6
+addx 1
+addx -21
+addx 22
+addx -38
+addx 5
+addx 3
+addx -1
+noop
+noop
+addx 5
+addx 1
+addx 4
+addx 3
+addx -2
+addx 2
+noop
+addx 7
+addx -1
+addx 2
+addx 4
+addx -10
+addx -19
+addx 35
+addx -1
+noop
+noop
+noop
diff --git a/day10.k b/day10.k
new file mode 100644
index 0000000..c57824f
--- /dev/null
+++ b/day10.k
@@ -0,0 +1,3 @@
+s:1,1+\,/{$["noop"~x;,0;0,.5_x]}'0:"day10"
++/a*s@-1+a:20+40*!6
+"@ "@1<{x|-x:x-!40}'6 40#s
diff --git a/day10.mew b/day10.mew
new file mode 100644
index 0000000..20e1285
--- /dev/null
+++ b/day10.mew
@@ -0,0 +1,31 @@
+(define (gscan f i g)
+  (gcombine (lambda (x i)
+              (let ((v (f i x)))
+                (values v v)))
+            i
+            g))
+
+(def xs 
+  (op=> (lines "day10")
+        (gmap (fun (line)
+                (if (=? line "noop")
+                  (generator 0)
+                  (generator 0 (=> (~? line "-?\\d+") car string->number)))) _)
+        gconcatenate
+        (gscan + 1 _)
+        (into #(1) _)))
+
+(op=> (range 20 221 40)
+      (gmap (op * (get xs (dec _)) _) _)
+      (inject +)
+      prn)
+
+(op=> (gen xs)
+      (ggroup _ 40)
+      (gtake _ 6)
+      (gmap (fun (line)
+              (into "" (gmap (fun (a b)
+                               (if (<= (abs (- a b)) 1) #\@ #\space))
+                             (gen line) (range 0))))
+            _)
+      (generator-for-each print _))
diff --git a/day10.rkt b/day10.rkt
new file mode 100644
index 0000000..846a8cc
--- /dev/null
+++ b/day10.rkt
@@ -0,0 +1,31 @@
+#lang racket
+
+(define (scan1 f i l)
+  (if (null? l)
+    l
+    (let ((v (f i (car l))))
+      (cons v (scan1 f v (cdr l))))))
+
+(define xs
+  (cons 1 (scan1 + 1
+            (append-map (lambda (insn)
+                          (match (string-split insn)
+                            [(list "noop") (list 0)]
+                            [(list "addx" sn) (list 0 (string->number sn))]))
+                        (file->lines "day10")))))
+
+(for/sum ([i (in-inclusive-range 20 220 40)])
+  (* i (list-ref xs (- i 1))))
+; 14160
+
+(let loop ([xs (take xs (* 6 40))])
+  (if (null? xs)
+    (void)
+    (let-values ([(line rest) (split-at xs 40)])
+      (displayln (list->string
+                  (map (lambda (a b)
+                         (if (<= (abs (- a b)) 1) #\@ #\space))
+                       line
+                       (range 0 40))))
+      (loop rest))))
+; RJERPEFC