You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
aoc-racket/2016/day15/lang.rkt

26 lines
857 B
Racket

8 years ago
#lang br/quicklang ;; http://adventofcode.com/2016/day/15
(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)
8 years ago
(with-pattern ([(DISC-ID ...) (generate-temporaries #'DISCS)]
8 years ago
[(DISC-SLOTS ...) #'DISCS])
8 years ago
#'(for/first ([DISC-ID (in-cycle DISC-SLOTS)] ...
8 years ago
[i (in-naturals)]
8 years ago
#:when (= 0 DISC-ID ...))
8 years ago
i)))
8 years ago
(require sugar/list)
(define-macro (disc TIME-OFFSET SIZE _ START)
8 years ago
#'(shift-left-cycle (range SIZE) (+ START TIME-OFFSET)))
8 years ago
(provide disc)