From 645fe19996740598ea04944992c59760338373b3 Mon Sep 17 00:00:00 2001 From: "Ruidy (aider)" Date: Tue, 3 Dec 2024 13:52:44 +0100 Subject: [PATCH] feat: Create initial files for Advent of Code 2024 Day 3 solution --- lib/advent_code2024/solutions/day03/day3.ex | 59 +++++++++++++++++++ lib/advent_code2024/solutions/day03/input.txt | 1 + .../solutions/day03/day3_test.exs | 28 +++++++++ 3 files changed, 88 insertions(+) create mode 100644 lib/advent_code2024/solutions/day03/day3.ex create mode 100644 lib/advent_code2024/solutions/day03/input.txt create mode 100644 test/advent_code2024/solutions/day03/day3_test.exs diff --git a/lib/advent_code2024/solutions/day03/day3.ex b/lib/advent_code2024/solutions/day03/day3.ex new file mode 100644 index 0000000..6e3ec72 --- /dev/null +++ b/lib/advent_code2024/solutions/day03/day3.ex @@ -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 diff --git a/lib/advent_code2024/solutions/day03/input.txt b/lib/advent_code2024/solutions/day03/input.txt new file mode 100644 index 0000000..1a30203 --- /dev/null +++ b/lib/advent_code2024/solutions/day03/input.txt @@ -0,0 +1 @@ +# Add your puzzle input here diff --git a/test/advent_code2024/solutions/day03/day3_test.exs b/test/advent_code2024/solutions/day03/day3_test.exs new file mode 100644 index 0000000..b13fbc8 --- /dev/null +++ b/test/advent_code2024/solutions/day03/day3_test.exs @@ -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