day 13 part 1

master
Matthew Butterick 4 years ago
parent cf853520be
commit 28bb4bfc2f

@ -0,0 +1,20 @@
#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)

@ -0,0 +1,2 @@
1000066
13,x,x,41,x,x,x,37,x,x,x,x,x,659,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,19,x,x,x,23,x,x,x,x,x,29,x,409,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,17