about summary refs log tree commit diff
path: root/day25.rkt
diff options
context:
space:
mode:
Diffstat (limited to 'day25.rkt')
-rw-r--r--day25.rkt32
1 files changed, 32 insertions, 0 deletions
diff --git a/day25.rkt b/day25.rkt
new file mode 100644
index 0000000..d3bc34a
--- /dev/null
+++ b/day25.rkt
@@ -0,0 +1,32 @@
+#lang racket
+(require srfi/1)
+
+(define data (for/list ([line (file->lines "day25")])
+               (for/list ([c line])
+                 (match c
+                   [#\2 2]
+                   [#\1 1]
+                   [#\0 0]
+                   [#\- -1]
+                   [#\= -2]))))
+
+(define (base5 ns)
+  (foldl (lambda (x a) (+ (* 5 a) x)) 0 ns))
+
+(define (unbase5 n)
+  (list->string (reverse (unfold zero?
+                                 (lambda (n) (match (modulo (+ n 2) 5)
+                                               [0 #\=]
+                                               [1 #\-]
+                                               [2 #\0]
+                                               [3 #\1]
+                                               [4 #\2]))
+                                 (lambda (n) (quotient (+ n 2) 5))
+                                 n))))
+
+; (map base5 data)
+
+(unbase5 (for/sum ([n data])
+           (base5 n)))
+
+;; "2-0-020-1==1021=--01"