start day16
parent
86ff9c26d0
commit
9bc43809ef
@ -0,0 +1,2 @@
|
||||
#lang reader "lang.rkt"
|
||||
35651584, 10010000000110000
|
@ -0,0 +1,2 @@
|
||||
#lang reader "lang.rkt"
|
||||
272, 10010000000110000
|
@ -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))))))
|
||||
|
@ -0,0 +1,2 @@
|
||||
#lang reader "lang.rkt"
|
||||
20, 10000
|
@ -0,0 +1,2 @@
|
||||
#lang reader "lang.rkt"
|
||||
12, 110010110100
|
Reference in New Issue