slightly less repetition in template
This commit is contained in:
parent
1b87681fda
commit
8d54cefbdd
1 changed files with 7 additions and 9 deletions
16
dayN.exs
16
dayN.exs
|
@ -28,16 +28,14 @@ defmodule DayREPLACE_ME do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp run_parts_with_timer(input) do
|
defp run_parts_with_timer(input) do
|
||||||
{p1_microsecs, p1_result} = :timer.tc(fn -> part1(input) end)
|
run_with_timer(1, fn -> part1(input) end)
|
||||||
IO.puts("Part 1 (completed in #{format_time(p1_microsecs)}):")
|
run_with_timer(2, fn -> part2(input) end)
|
||||||
IO.write("\n")
|
end
|
||||||
IO.puts(p1_result)
|
|
||||||
IO.write("\n")
|
|
||||||
|
|
||||||
{p2_microsecs, p2_result} = :timer.tc(fn -> part2(input) end)
|
defp run_with_timer(part, fun) do
|
||||||
IO.puts("Part 2 (completed in #{format_time(p2_microsecs)}):")
|
{time, result} = :timer.tc(fun)
|
||||||
IO.write("\n")
|
IO.puts("Part #{part} (completed in #{format_time(time)}):\n")
|
||||||
IO.puts(p2_result)
|
IO.puts("#{result}\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
defp format_time(μsec) when μsec < 1_000, do: "#{μsec}μs"
|
defp format_time(μsec) when μsec < 1_000, do: "#{μsec}μs"
|
||||||
|
|
Loading…
Reference in a new issue