My julia solutions for Advent of Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
509 B

  1. # https://adventofcode.com/2020/day/13
  2. using AdventOfCode
  3. using Mods
  4. t_str, buses_str = readlines("2020/data/day_13.txt")
  5. time = parse(Int, t_str)
  6. buses = map(x->x=="x" ? nothing : parse(Int, x), split(buses_str, ','))
  7. function part_1()
  8. wait, bus = min(map(x->(x*ceil(time / x), x), filter(!isnothing, buses))...)
  9. (wait - time) * bus
  10. end
  11. @info part_1()
  12. function part_2()
  13. mods = map(k->Mod{buses[k]}(-(k-1)), filter(k->!isnothing(buses[k]), keys(buses)))
  14. CRT(mods...).val
  15. end
  16. @info part_2()