mirror of
https://github.com/rjNemo/ai_advent_code_2024
synced 2026-06-10 04:26:47 +00:00
feat: Add solve_day1_part2 function and test for Day 1 Part 2
This commit is contained in:
parent
fee5ec25f3
commit
dc74c4a7b1
2 changed files with 19 additions and 0 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue