day15
parent
95b784f621
commit
107965d5ee
@ -0,0 +1,8 @@
|
|||||||
|
#lang reader "lang.rkt"
|
||||||
|
Disc #1 has 5 positions; at time=0, it is at position 2.
|
||||||
|
Disc #2 has 13 positions; at time=0, it is at position 7.
|
||||||
|
Disc #3 has 17 positions; at time=0, it is at position 10.
|
||||||
|
Disc #4 has 3 positions; at time=0, it is at position 2.
|
||||||
|
Disc #5 has 19 positions; at time=0, it is at position 9.
|
||||||
|
Disc #6 has 7 positions; at time=0, it is at position 0.
|
||||||
|
Disc #7 has 11 positions; at time=0, it is at position 0.
|
@ -0,0 +1,7 @@
|
|||||||
|
#lang reader "lang.rkt"
|
||||||
|
Disc #1 has 5 positions; at time=0, it is at position 2.
|
||||||
|
Disc #2 has 13 positions; at time=0, it is at position 7.
|
||||||
|
Disc #3 has 17 positions; at time=0, it is at position 10.
|
||||||
|
Disc #4 has 3 positions; at time=0, it is at position 2.
|
||||||
|
Disc #5 has 19 positions; at time=0, it is at position 9.
|
||||||
|
Disc #6 has 7 positions; at time=0, it is at position 0.
|
@ -0,0 +1,27 @@
|
|||||||
|
#lang br/quicklang ;; http://adventofcode.com/2016/day/15
|
||||||
|
(require openssl/md5)
|
||||||
|
(provide read-syntax
|
||||||
|
(rename-out [mb #%module-begin]))
|
||||||
|
|
||||||
|
(define (read-syntax path port)
|
||||||
|
(strip-bindings
|
||||||
|
#`(module mod "lang.rkt"
|
||||||
|
#,@(for/list ([line (in-list (string-split (port->string port) "\n"))])
|
||||||
|
`(disc ,@(map string->number (regexp-match* #px"\\d+" line)))))))
|
||||||
|
|
||||||
|
(define-macro (mb . DISCS)
|
||||||
|
#'(#%module-begin
|
||||||
|
(solve . DISCS)))
|
||||||
|
|
||||||
|
(define-macro (solve . DISCS)
|
||||||
|
(with-pattern ([(DISC# ...) (generate-temporaries #'DISCS)]
|
||||||
|
[(DISC-SLOTS ...) #'DISCS])
|
||||||
|
#'(for/or ([DISC# (in-cycle DISC-SLOTS)] ...
|
||||||
|
[i (in-naturals)]
|
||||||
|
#:when (= DISC# ...))
|
||||||
|
i)))
|
||||||
|
|
||||||
|
(require sugar/list)
|
||||||
|
(define-macro (disc TIME-OFFSET SIZE _ START)
|
||||||
|
#'(shift (range SIZE) (modulo (- (+ START TIME-OFFSET)) SIZE) #f #t))
|
||||||
|
(provide disc)
|
@ -0,0 +1,3 @@
|
|||||||
|
#lang reader "lang.rkt"
|
||||||
|
Disc #1 has 5 positions; at time=0, it is at position 4.
|
||||||
|
Disc #2 has 2 positions; at time=0, it is at position 1.
|
Reference in New Issue