From 9bc43809efeb983f8aad0f1062282164982b3ba9 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 16 Dec 2016 22:31:25 -0800 Subject: [PATCH] start day16 --- 2016/day16/input-b.rkt | 2 ++ 2016/day16/input.rkt | 2 ++ 2016/day16/lang.rkt | 38 ++++++++++++++++++++++++++++++++++++++ 2016/day16/test-b.rkt | 2 ++ 2016/day16/test.rkt | 2 ++ 5 files changed, 46 insertions(+) create mode 100644 2016/day16/input-b.rkt create mode 100644 2016/day16/input.rkt create mode 100644 2016/day16/lang.rkt create mode 100644 2016/day16/test-b.rkt create mode 100644 2016/day16/test.rkt diff --git a/2016/day16/input-b.rkt b/2016/day16/input-b.rkt new file mode 100644 index 0000000..c37fcbe --- /dev/null +++ b/2016/day16/input-b.rkt @@ -0,0 +1,2 @@ +#lang reader "lang.rkt" +35651584, 10010000000110000 \ No newline at end of file diff --git a/2016/day16/input.rkt b/2016/day16/input.rkt new file mode 100644 index 0000000..fbd18e6 --- /dev/null +++ b/2016/day16/input.rkt @@ -0,0 +1,2 @@ +#lang reader "lang.rkt" +272, 10010000000110000 \ No newline at end of file diff --git a/2016/day16/lang.rkt b/2016/day16/lang.rkt new file mode 100644 index 0000000..d7ea2e6 --- /dev/null +++ b/2016/day16/lang.rkt @@ -0,0 +1,38 @@ +#lang br/quicklang ;; http://adventofcode.com/2016/day/16 +(require openssl/md5) +(provide read-syntax + (rename-out [mb #%module-begin])) + +(define (read-syntax path port) + (strip-bindings + #`(module mod "lang.rkt" + #,@(string-split (string-trim (port->string port)) ", ")))) + +(define-macro (mb SIZE INIT) + #'(#%module-begin + (display (list->string (checksum (fill-disk (string->list INIT) (string->number SIZE))))))) + +(define (dragonize cs) + (append cs '(#\0) + (for/list ([c (in-list (reverse cs))]) + (if (eqv? c #\1) + #\0 + #\1)))) + +(define (fill-disk init size) + (let loop ([cs init]) + (if (>= (length cs) size) + (take cs size) + (loop (dragonize cs))))) + +(require sugar/list) +(define (checksum cs) + (let loop ([cs cs]) + (if (odd? (length cs)) + cs + (loop + (for/list ([match (in-list (slice-at cs 2))]) + (if (member match '((#\0 #\0) (#\1 #\1))) + #\1 + #\0)))))) + diff --git a/2016/day16/test-b.rkt b/2016/day16/test-b.rkt new file mode 100644 index 0000000..238af15 --- /dev/null +++ b/2016/day16/test-b.rkt @@ -0,0 +1,2 @@ +#lang reader "lang.rkt" +20, 10000 \ No newline at end of file diff --git a/2016/day16/test.rkt b/2016/day16/test.rkt new file mode 100644 index 0000000..93b5eb8 --- /dev/null +++ b/2016/day16/test.rkt @@ -0,0 +1,2 @@ +#lang reader "lang.rkt" +12, 110010110100 \ No newline at end of file