diff --git a/2016/day15/input-b.rkt b/2016/day15/input-b.rkt new file mode 100644 index 0000000..51d7764 --- /dev/null +++ b/2016/day15/input-b.rkt @@ -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. \ No newline at end of file diff --git a/2016/day15/input.rkt b/2016/day15/input.rkt new file mode 100644 index 0000000..d259a96 --- /dev/null +++ b/2016/day15/input.rkt @@ -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. \ No newline at end of file diff --git a/2016/day15/lang.rkt b/2016/day15/lang.rkt new file mode 100644 index 0000000..11ea01d --- /dev/null +++ b/2016/day15/lang.rkt @@ -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) \ No newline at end of file diff --git a/2016/day15/test.rkt b/2016/day15/test.rkt new file mode 100644 index 0000000..4a873c0 --- /dev/null +++ b/2016/day15/test.rkt @@ -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. \ No newline at end of file