Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
code-shoily committed Aug 17, 2024
1 parent 98db404 commit 1613ca5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
16 changes: 10 additions & 6 deletions lib/advent_of_code.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ defmodule AdventOfCode do
"""
@spec solve(year(), day()) :: {any(), any()}
def solve(year, day, rust? \\ false) do
solution = :timer.tc(fn ->
case rust? do
true ->
solution =
:timer.tc(fn ->
case rust? do
true ->
{_, result} = AdventOfCode.RustNif.solve(year, day)
result
false -> Module.concat([AdventOfCode, get_year_module(year), get_day_module(day)]).run()
end
end)

false ->
Module.concat([AdventOfCode, get_year_module(year), get_day_module(day)]).run()
end
end)

{:ok, solution}
rescue
_ in FunctionClauseError -> {:error, :invalid_args}
Expand Down
11 changes: 8 additions & 3 deletions lib/mix/tasks/solve.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ defmodule Mix.Tasks.Solve do
case InputParser.parse(args) do
{year, day} ->
case AdventOfCode.solve(year, day, false) do
{:ok, {time, {part_1, part_2}}} -> Mix.shell().info("Part 1: #{part_1}\tPart 2: #{part_2}\tTime: #{time} µs")
{:error, :not_yet_solved} -> Mix.shell().error("#{year}/#{day} is not solved yet")
{:error, :invalid_args} -> Mix.shell().error("Invalid year/day: #{year}/#{day}")
{:ok, {time, {part_1, part_2}}} ->
Mix.shell().info("Part 1: #{part_1}\tPart 2: #{part_2}\tTime: #{time} µs")

{:error, :not_yet_solved} ->
Mix.shell().error("#{year}/#{day} is not solved yet")

{:error, :invalid_args} ->
Mix.shell().error("Invalid year/day: #{year}/#{day}")
end

_ ->
Expand Down

0 comments on commit 1613ca5

Please sign in to comment.