1
0
Fork 0
adventofcode/src/13.rkt

22 lines
634 B
Racket
Raw Normal View History

2020-12-13 06:41:31 +00:00
#lang curly-fn racket
(require math/number-theory
"../lib.rkt")
(define input (problem-input 13))
(define timestamp (string->number (first input)))
(define busses (map string->number (string-split (second input) ",")))
(define ids (filter identity busses))
(define part1
(let* ([waits (map #{- (* % (add1 (quotient timestamp %))) timestamp} ids)]
[wait (apply min waits)]
[index (index-of waits wait)])
(* wait (list-ref ids index))))
(define part2
(let ([offsets (filter-map #{and %1 (negate %2)} busses (range (length busses)))])
(solve-chinese offsets ids)))
(show-solution part1 part2)