mirror of
https://github.com/rjNemo/ai_advent_code_2024
synced 2026-06-12 13:36:39 +00:00
fix: Update solve/1 to handle both file paths and direct content
This commit is contained in:
parent
d200c5b512
commit
ed6da53845
1 changed files with 9 additions and 3 deletions
|
|
@ -12,11 +12,17 @@ defmodule AdventCode2024.Solutions.Day2 do
|
||||||
def solve(input \\ @default_input)
|
def solve(input \\ @default_input)
|
||||||
def solve(""), do: {:error, :no_valid_reports}
|
def solve(""), do: {:error, :no_valid_reports}
|
||||||
def solve(input) when is_binary(input) and input != "" do
|
def solve(input) when is_binary(input) and input != "" do
|
||||||
|
if String.contains?(input, "\n") or !String.contains?(input, "/") do
|
||||||
|
# Input is content
|
||||||
|
solve_content(input)
|
||||||
|
else
|
||||||
|
# Input is file path
|
||||||
case File.read(input) do
|
case File.read(input) do
|
||||||
{:ok, content} -> solve_content(content)
|
{:ok, content} -> solve_content(content)
|
||||||
{:error, reason} -> {:error, reason}
|
{:error, reason} -> {:error, reason}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp solve_content(""), do: {:error, :no_valid_reports}
|
defp solve_content(""), do: {:error, :no_valid_reports}
|
||||||
defp solve_content(content) when is_binary(content) and content != "" do
|
defp solve_content(content) when is_binary(content) and content != "" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue