2023-12-02 06:00:28 +00:00
|
|
|
#!/usr/bin/env elixir
|
2022-11-27 09:04:58 +00:00
|
|
|
defmodule DayREPLACE_ME do
|
|
|
|
def part1(input) do
|
|
|
|
input
|
|
|
|
end
|
|
|
|
|
2022-11-27 15:28:42 +00:00
|
|
|
def part2(_input) do
|
2024-12-22 09:35:39 +00:00
|
|
|
:not_implemented
|
2022-11-27 09:04:58 +00:00
|
|
|
end
|
|
|
|
|
2022-11-27 15:28:42 +00:00
|
|
|
def input do
|
2022-11-27 09:04:58 +00:00
|
|
|
with [input_filename] <- System.argv(),
|
|
|
|
{:ok, input} <- File.read(input_filename) do
|
2022-11-27 15:28:42 +00:00
|
|
|
input
|
2022-11-27 09:04:58 +00:00
|
|
|
else
|
2022-11-27 16:20:58 +00:00
|
|
|
_ -> :error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# HERE BE BOILERPLATE #
|
|
|
|
#######################
|
|
|
|
|
|
|
|
def run do
|
|
|
|
case input() do
|
|
|
|
:error -> print_usage()
|
|
|
|
input -> run_parts_with_timer(input)
|
2022-11-27 09:04:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-27 17:16:26 +00:00
|
|
|
defp run_parts_with_timer(input) do
|
2022-11-28 01:18:27 +00:00
|
|
|
run_with_timer(1, fn -> part1(input) end)
|
|
|
|
run_with_timer(2, fn -> part2(input) end)
|
|
|
|
end
|
|
|
|
|
|
|
|
defp run_with_timer(part, fun) do
|
|
|
|
{time, result} = :timer.tc(fun)
|
|
|
|
IO.puts("Part #{part} (completed in #{format_time(time)}):\n")
|
2024-12-22 09:35:39 +00:00
|
|
|
IO.puts("#{inspect(result)}\n")
|
2022-11-27 09:04:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
defp format_time(μsec) when μsec < 1_000, do: "#{μsec}μs"
|
|
|
|
defp format_time(μsec) when μsec < 1_000_000, do: "#{μsec / 1000}ms"
|
2022-11-28 01:24:06 +00:00
|
|
|
defp format_time(μsec), do: "#{μsec / 1_000_000}s"
|
2022-11-27 09:04:58 +00:00
|
|
|
|
|
|
|
defp print_usage do
|
|
|
|
IO.puts("Usage: elixir dayREPLACE_ME.exs input_filename")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-27 16:20:58 +00:00
|
|
|
# DayREPLACE_ME.run()
|