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/2017/d13/main.rkt

26 lines
894 B
Racket

7 years ago
#lang reader "../aoc-lang.rkt"
(require (for-syntax racket/string racket/sequence) racket/dict)
(provide (rename-out [#%mb #%module-begin]) ★★)
(define-macro (#%mb (STARS) (DEPTH: RANGE) ...)
(with-pattern ([(DEPTH ...)
(for/list ([id (in-syntax #'(DEPTH: ...))])
(string->number (string-trim (symbol->string (syntax->datum id)) ":")))])
7 years ago
#'(#%module-begin (time (STARS '(DEPTH ...) '(RANGE ...))))))
7 years ago
(define (caught? depth range [delay 0])
(zero? (modulo (+ depth delay) (* 2 (sub1 range)))))
(define ( ds rs)
(for/sum ([d (in-list ds)]
[r (in-list rs)]
#:when (caught? d r))
(* d r)))
(define (★★ ds rs)
(for/first ([delay (in-naturals)]
#:unless (for/or ([d (in-list ds)]
[r (in-list rs)])
(caught? d r delay)))
delay))