mirror of
https://github.com/rjNemo/ai_advent_code_2024
synced 2026-06-06 02:26:44 +00:00
fix: Improve file path handling in Day03.solve/1
This commit is contained in:
parent
ea60e261ff
commit
5958552501
1 changed files with 3 additions and 6 deletions
|
|
@ -14,17 +14,14 @@ defmodule AdventCode2024.Solutions.Day03 do
|
||||||
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
|
||||||
cond do
|
cond do
|
||||||
String.contains?(input, "\n") ->
|
# If it looks like a file path and doesn't contain newlines
|
||||||
# Input is multiline content
|
String.contains?(input, "/") and not String.contains?(input, "\n") ->
|
||||||
solve_content(input)
|
|
||||||
String.contains?(input, "/") ->
|
|
||||||
# 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
|
||||||
|
# If it's not a file path or contains newlines, treat as content
|
||||||
true ->
|
true ->
|
||||||
# Input is single line content
|
|
||||||
solve_content(input)
|
solve_content(input)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue