aoc-2020-zig

Advent of Code 2020 Solutions in Zig
git clone https://git.sinitax.com/sinitax/aoc-2020-zig
Log | Files | Refs | README | sfeed.txt

part1 (3214B)


      1--- Day 13: Shuttle Search ---
      2
      3Your ferry can make it safely to a nearby port, but it won't get much further. When you call to book
      4another ship, you discover that no ships embark from that port to your vacation island. You'll need
      5to get from the port to the nearest airport.
      6
      7Fortunately, a shuttle bus service is available to bring you from the sea port to the airport!  Each
      8bus has an ID number that also indicates how often the bus leaves for the airport.
      9
     10Bus schedules are defined based on a timestamp that measures the number of
     11minutes since some fixed reference point in the past. At timestamp 0, every bus simultaneously
     12departed from the sea port. After that, each bus travels to the airport, then various other
     13locations, and finally returns to the sea port to repeat its journey forever.
     14
     15The time this loop takes a particular bus is also its ID number: the bus with ID 5 departs from the
     16sea port at timestamps 0, 5, 10, 15, and so on. The bus with ID 11 departs at 0, 11, 22, 33, and so
     17on. If you are there when the bus departs, you can ride that bus to the airport!
     18
     19Your notes (your puzzle input) consist of two lines.  The first line is your estimate of the
     20earliest timestamp you could depart on a bus. The second line lists the bus IDs that
     21are in service according to the shuttle company; entries that show x must be out of service, so you
     22decide to ignore them.
     23
     24To save time once you arrive, your goal is to figure out the earliest bus you can take to
     25the airport. (There will be exactly one such bus.)
     26
     27For example, suppose you have the following notes:
     28
     29939
     307,13,x,x,59,x,31,19
     31
     32Here, the earliest timestamp you could depart is 939, and the bus IDs in service are 7, 13, 59, 31,
     33and 19. Near timestamp 939, these bus IDs depart at the times marked D:
     34
     35time   bus 7   bus 13  bus 59  bus 31  bus 19
     36929      .       .       .       .       .
     37930      .       .       .       D       .
     38931      D       .       .       .       D
     39932      .       .       .       .       .
     40933      .       .       .       .       .
     41934      .       .       .       .       .
     42935      .       .       .       .       .
     43936      .       D       .       .       .
     44937      .       .       .       .       .
     45938      D       .       .       .       .
     46939      .       .       .       .       .
     47940      .       .       .       .       .
     48941      .       .       .       .       .
     49942      .       .       .       .       .
     50943      .       .       .       .       .
     51944      .       .       D       .       .
     52945      D       .       .       .       .
     53946      .       .       .       .       .
     54947      .       .       .       .       .
     55948      .       .       .       .       .
     56949      .       D       .       .       .
     57
     58The earliest bus you could take is bus ID 59. It doesn't depart until timestamp 944, so you would
     59need to wait 944 - 939 = 5 minutes before it departs. Multiplying the bus ID by the number of
     60minutes you'd need to wait gives 295.
     61
     62What is the ID of the earliest bus you can take to the airport multiplied by the number of
     63minutes you'll need to wait for that bus?
     64
     65