AdventOfCode/2020/elixir/day13/day13part1.exs

20 lines
466 B
Elixir
Raw Normal View History

2020-12-13 13:17:33 +00:00
defmodule Day13Part1 do
def run do
File.read!("input")
|> String.split(["\n", ","], trim: true)
|> Enum.reject(&(&1 == "x"))
|> Enum.map(&String.to_integer/1)
|> earliest_bus()
|> (fn {id, time} -> id * time end).()
|> IO.puts()
end
def earliest_bus([now | busses]) do
busses
|> Enum.map(fn bus -> {bus, bus - rem(now, bus)} end)
|> Enum.min(fn {_, time1}, {_, time2} -> time1 <= time2 end)
end
end
Day13Part1.run()