mirror of
https://github.com/rjNemo/ai_advent_code_2024
synced 2026-06-06 02:26:44 +00:00
feat: Create initial files for Advent of Code 2024 Day 3 solution
This commit is contained in:
parent
90bfa75b3a
commit
645fe19996
3 changed files with 88 additions and 0 deletions
59
lib/advent_code2024/solutions/day03/day3.ex
Normal file
59
lib/advent_code2024/solutions/day03/day3.ex
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
defmodule AdventCode2024.Solutions.Day03 do
|
||||
@moduledoc """
|
||||
Solution for Advent of Code 2024, Day 3
|
||||
"""
|
||||
|
||||
@behaviour AdventCode2024.Solution
|
||||
|
||||
@default_input "lib/advent_code2024/solutions/day03/input.txt"
|
||||
|
||||
@doc """
|
||||
Solve part 1 of the challenge
|
||||
"""
|
||||
def solve(input \\ @default_input)
|
||||
def solve(""), do: {:error, :no_input}
|
||||
def solve(input) when is_binary(input) and input != "" do
|
||||
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
|
||||
|
||||
@doc """
|
||||
Solve part 2 of the challenge
|
||||
"""
|
||||
def solve_part2(input \\ @default_input)
|
||||
def solve_part2(""), do: {:error, :no_input}
|
||||
def solve_part2(input) when is_binary(input) and input != "" do
|
||||
if String.contains?(input, "\n") or !String.contains?(input, "/") do
|
||||
# Input is content
|
||||
solve_part2_content(input)
|
||||
else
|
||||
# Input is file path
|
||||
case File.read(input) do
|
||||
{:ok, content} -> solve_part2_content(content)
|
||||
{:error, reason} -> {:error, reason}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Private functions
|
||||
|
||||
defp solve_content(""), do: {:error, :no_input}
|
||||
defp solve_content(content) when is_binary(content) and content != "" do
|
||||
# TODO: Implement solution for part 1
|
||||
{:ok, 0}
|
||||
end
|
||||
|
||||
defp solve_part2_content(""), do: {:error, :no_input}
|
||||
defp solve_part2_content(content) when is_binary(content) and content != "" do
|
||||
# TODO: Implement solution for part 2
|
||||
{:ok, 0}
|
||||
end
|
||||
end
|
||||
1
lib/advent_code2024/solutions/day03/input.txt
Normal file
1
lib/advent_code2024/solutions/day03/input.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
# Add your puzzle input here
|
||||
28
test/advent_code2024/solutions/day03/day3_test.exs
Normal file
28
test/advent_code2024/solutions/day03/day3_test.exs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
defmodule AdventCode2024.Solutions.Day03Test do
|
||||
use ExUnit.Case
|
||||
alias AdventCode2024.Solutions.Day03
|
||||
|
||||
describe "solve/1" do
|
||||
test "returns error for empty input" do
|
||||
assert Day03.solve("") == {:error, :no_input}
|
||||
end
|
||||
|
||||
test "returns error for invalid file" do
|
||||
assert Day03.solve("nonexistent.txt") == {:error, :enoent}
|
||||
end
|
||||
|
||||
# TODO: Add more specific tests for part 1
|
||||
end
|
||||
|
||||
describe "solve_part2/1" do
|
||||
test "returns error for empty input" do
|
||||
assert Day03.solve_part2("") == {:error, :no_input}
|
||||
end
|
||||
|
||||
test "returns error for invalid file" do
|
||||
assert Day03.solve_part2("nonexistent.txt") == {:error, :enoent}
|
||||
end
|
||||
|
||||
# TODO: Add more specific tests for part 2
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue