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(input \\ @default_input)
|
||||||
def solve(""), do: {:error, :no_input}
|
def solve(""), do: {:error, :no_input}
|
||||||
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
|
cond do
|
||||||
# Input is content
|
String.contains?(input, "\n") ->
|
||||||
solve_content(input)
|
# Input is multiline content
|
||||||
else
|
solve_content(input)
|
||||||
# Input is file path
|
String.contains?(input, "/") ->
|
||||||
case File.read(input) do
|
# Input is file path
|
||||||
{:ok, content} -> solve_content(content)
|
case File.read(input) do
|
||||||
{:error, reason} -> {:error, reason}
|
{:ok, content} -> solve_content(content)
|
||||||
end
|
{:error, reason} -> {:error, reason}
|
||||||
|
end
|
||||||
|
true ->
|
||||||
|
# Input is single line content
|
||||||
|
solve_content(input)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue