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/2020/13.rkt

20 lines
516 B
Racket

#lang br
(require racket/file rackunit)
(match-define (cons target buses-all)
(for/list ([tok
(in-port read
(open-input-string
(string-replace (file->string "13.rktd") "," " ")))])
tok))
(define buses (filter integer? buses-all))
(define (overshoot bus)
(for/last ([i (in-naturals)]
#:final (> (* i bus) target))
(- (* i bus) target)))
(define winner (argmin overshoot buses))
(check-equal? (* winner (overshoot winner)) 246)