mirror of
https://github.com/rjNemo/ai_advent_code_2024
synced 2026-06-12 05:26:39 +00:00
refactor: Improve error handling in solve and solve_part2 functions
This commit is contained in:
parent
85ebc05ead
commit
c1fc39ac17
1 changed files with 12 additions and 8 deletions
|
|
@ -29,10 +29,12 @@ defmodule AdventCode2024.Day1 do
|
||||||
def solve(input_file \\ "day1/input.txt") do
|
def solve(input_file \\ "day1/input.txt") do
|
||||||
case File.read(input_file) do
|
case File.read(input_file) do
|
||||||
{:ok, content} ->
|
{:ok, content} ->
|
||||||
{left, right} = parse_input(content)
|
case parse_input(content) do
|
||||||
result = calculate_total_distance(left, right)
|
{:error, reason} -> {:error, reason}
|
||||||
{:ok, result}
|
{left, right} ->
|
||||||
|
result = calculate_total_distance(left, right)
|
||||||
|
{:ok, result}
|
||||||
|
end
|
||||||
{:error, reason} ->
|
{:error, reason} ->
|
||||||
{:error, reason}
|
{:error, reason}
|
||||||
end
|
end
|
||||||
|
|
@ -61,10 +63,12 @@ defmodule AdventCode2024.Day1 do
|
||||||
def solve_part2(input_file \\ "day1/input.txt") do
|
def solve_part2(input_file \\ "day1/input.txt") do
|
||||||
case File.read(input_file) do
|
case File.read(input_file) do
|
||||||
{:ok, content} ->
|
{:ok, content} ->
|
||||||
{left, right} = parse_input(content)
|
case parse_input(content) do
|
||||||
result = calculate_similarity_score(left, right)
|
{:error, reason} -> {:error, reason}
|
||||||
{:ok, result}
|
{left, right} ->
|
||||||
|
result = calculate_similarity_score(left, right)
|
||||||
|
{:ok, result}
|
||||||
|
end
|
||||||
{:error, reason} ->
|
{:error, reason} ->
|
||||||
{:error, reason}
|
{:error, reason}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue