feat: Add solve_day1_part2 function and test for Day 1 Part 2

This commit is contained in:
Ruidy (aider) 2024-12-01 10:15:53 +01:00
parent fee5ec25f3
commit dc74c4a7b1
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
2 changed files with 19 additions and 0 deletions

View file

@ -17,6 +17,20 @@ defmodule AdventCode2024 do
end
end
@doc """
Reads the input file for day 1 part 2 and calculates the similarity score between the two lists.
Returns {:ok, result} if successful, {:error, reason} if there's an error.
"""
def solve_day1_part2(input_file \\ "day1/input.txt") do
case File.read(input_file) do
{:ok, content} ->
{left_list, right_list} = parse_input(content)
result = calculate_similarity_score(left_list, right_list)
{:ok, result}
{:error, reason} -> {:error, reason}
end
end
@doc """
Parses the input string into two lists of numbers.
Input format is expected to be tab-separated numbers, one pair per line.

View file

@ -51,5 +51,10 @@ defmodule AdventCode2024Test do
test "handles lists with all matches" do
assert AdventCode2024.calculate_similarity_score([1, 1], [1, 1]) == 4
end
test "solves day 1 part 2 puzzle with actual input file" do
assert {:ok, result} = AdventCode2024.solve_day1_part2()
assert is_integer(result)
end
end
end