mirror of
https://github.com/rjNemo/ai_advent_code_2024
synced 2026-06-06 02:26:44 +00:00
fix: Improve file input handling in Day03 solution
This commit is contained in:
parent
70b2cf2086
commit
ea60e261ff
1 changed files with 13 additions and 9 deletions
|
|
@ -13,15 +13,19 @@ defmodule AdventCode2024.Solutions.Day03 do
|
|||
def solve(input \\ @default_input)
|
||||
def solve(""), do: {:error, :no_input}
|
||||
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
|
||||
{:ok, content} -> solve_content(content)
|
||||
{:error, reason} -> {:error, reason}
|
||||
end
|
||||
cond do
|
||||
String.contains?(input, "\n") ->
|
||||
# Input is multiline content
|
||||
solve_content(input)
|
||||
String.contains?(input, "/") ->
|
||||
# Input is file path
|
||||
case File.read(input) do
|
||||
{:ok, content} -> solve_content(content)
|
||||
{:error, reason} -> {:error, reason}
|
||||
end
|
||||
true ->
|
||||
# Input is single line content
|
||||
solve_content(input)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue