about summary refs log tree commit diff
path: root/day10.mew
diff options
context:
space:
mode:
Diffstat (limited to 'day10.mew')
-rw-r--r--day10.mew31
1 files changed, 31 insertions, 0 deletions
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 _))