From ed6da53845a8bad240c4f6c80865b89e5c05683d Mon Sep 17 00:00:00 2001 From: "Ruidy (aider)" Date: Mon, 2 Dec 2024 08:17:51 +0100 Subject: [PATCH] fix: Update solve/1 to handle both file paths and direct content --- lib/advent_code2024/solutions/day02/day2.ex | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/advent_code2024/solutions/day02/day2.ex b/lib/advent_code2024/solutions/day02/day2.ex index d4aff3c..2874399 100644 --- a/lib/advent_code2024/solutions/day02/day2.ex +++ b/lib/advent_code2024/solutions/day02/day2.ex @@ -12,9 +12,15 @@ defmodule AdventCode2024.Solutions.Day2 do def solve(input \\ @default_input) def solve(""), do: {:error, :no_valid_reports} def solve(input) when is_binary(input) and input != "" do - case File.read(input) do - {:ok, content} -> solve_content(content) - {:error, reason} -> {:error, reason} + 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 end end