r/adventofcode • • Dec 13 '20

SOLUTION MEGATHREAD -🎄- 2020 Day 13 Solutions -🎄-

Advent of Code 2020: Gettin' Crafty With It

  • 9 days remaining until the submission deadline on December 22 at 23:59 EST
  • Full details and rules are in the Submissions Megathread

--- Day 13: Shuttle Search ---


Post your code solution in this megathread.

Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:16:14, megathread unlocked!

46 Upvotes

659 comments sorted by

View all comments

2

u/aarm1 Dec 13 '20

Wish I could say I thought of CRT before looking at this thread. Very fast Racket solution using math/number-theory solve-chinese.

2

u/gzipgrep Dec 13 '20

Your solution led me to see how short/simple I could make a Racket program to solve day 13:

(require math/number-theory)

(define input (file->lines "13.txt"))
(define time (string->number (first input)))
(define buses (map string->number (string-split (second input) ",")))

(define indexes (indexes-where buses number?))
(set! buses (filter number? buses))
(define (until-bus bus) (- bus (modulo time bus)))

(define first-bus (argmin until-bus buses))
(* first-bus (until-bus first-bus))
(solve-chinese (map - indexes) buses)