1
0
Fork 0
This commit is contained in:
Jonathan Chan 2020-12-12 22:41:31 -08:00 committed by Jonathan Chan
parent 637477664a
commit 41f9a58993
2 changed files with 23 additions and 0 deletions

2
input/13.txt Normal file
View File

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

21
src/13.rkt Normal file
View File

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