From 03f9fa40853804d1d60381d189bcf8e5bb7ad07c Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Tue, 27 Dec 2022 12:12:38 +0100 Subject: day25 --- day25.rkt | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 day25.rkt (limited to 'day25.rkt') 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" -- cgit 1.4.1