Browse Source

Finished 2020 day 13

main
Micah Halter 4 months ago
parent
commit
7d9f3e29d8
Signed by: mehalter GPG Key ID: 4224A6EA9A8CAAA8
  1. 2
      2020/data/day_13.txt
  2. 3
      2020/src/day_12.jl
  3. 19
      2020/src/day_13.jl
  4. 1
      Project.toml

2
2020/data/day_13.txt

@ -0,0 +1,2 @@
1008832
23,x,x,x,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,x,449,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,13,19,x,x,x,x,x,x,x,x,x,29,x,991,x,x,x,x,x,37,x,x,x,x,x,x,x,x,x,x,17

3
2020/src/day_12.jl

@ -11,8 +11,7 @@ function step_ship(inst, pos, dir, part_2=false)
pos += val*dir
elseif comm == 'R' || comm == 'L'
s,c = map(x->Int(round(x(deg2rad(val)))), [sin, cos])
dir *= comm == 'R' ? [c -s; s c] :
[c s; -s c]
dir *= comm == 'R' ? [c -s; s c] : [c s; -s c]
elseif !part_2
pos += val*dirs[comm]
else

19
2020/src/day_13.jl

@ -0,0 +1,19 @@
# https://adventofcode.com/2020/day/13
using AdventOfCode
using Mods
t_str, buses_str = readlines("2020/data/day_13.txt")
time = parse(Int, t_str)
buses = map(x->x=="x" ? nothing : parse(Int, x), split(buses_str, ','))
function part_1()
wait, bus = min(map(x->(x*ceil(time / x), x), filter(!isnothing, buses))...)
(wait - time) * bus
end
@info part_1()
function part_2()
mods = map(k->Mod{buses[k]}(-(k-1)), filter(k->!isnothing(buses[k]), keys(buses)))
CRT(mods...).val
end
@info part_2()

1
Project.toml

@ -2,3 +2,4 @@
AdventOfCode = "7ef4cfdd-3fec-4d8b-b242-bcc5161d01d5"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
MD5 = "6ac74813-4b46-53a4-afec-0b5dc9d7885c"
Mods = "7475f97c-0381-53b1-977b-4c60186c8d62"
Loading…
Cancel
Save