From 2d73d1bb51329245ce1707161756b0b67074425d Mon Sep 17 00:00:00 2001 From: Ruidy Date: Thu, 5 Dec 2024 10:16:12 +0100 Subject: [PATCH] chore: scaffold day5 --- lib/advent_code2024/solutions/day05/README.md | 7 +++ lib/advent_code2024/solutions/day05/day5.ex | 62 +++++++++++++++++++ priv/inputs/day05/input.txt | 1 + 3 files changed, 70 insertions(+) create mode 100644 lib/advent_code2024/solutions/day05/README.md create mode 100644 lib/advent_code2024/solutions/day05/day5.ex create mode 100644 priv/inputs/day05/input.txt diff --git a/lib/advent_code2024/solutions/day05/README.md b/lib/advent_code2024/solutions/day05/README.md new file mode 100644 index 0000000..c96f456 --- /dev/null +++ b/lib/advent_code2024/solutions/day05/README.md @@ -0,0 +1,7 @@ +# Day 5: Title + +[Read the problem](https://adventofcode.com/2024/day/5) + +## Part 1 + +## Part 2 diff --git a/lib/advent_code2024/solutions/day05/day5.ex b/lib/advent_code2024/solutions/day05/day5.ex new file mode 100644 index 0000000..c2d5aff --- /dev/null +++ b/lib/advent_code2024/solutions/day05/day5.ex @@ -0,0 +1,62 @@ +defmodule AdventCode2024.Solutions.Day5 do + @moduledoc """ + Day 5: Solution for Advent of Code 2024 + """ + + @behaviour AdventCode2024.Solution + + @default_input "priv/inputs/day05/input.txt" + + @doc """ + Solve part 1 of the challenge + """ + def solve(input_file \\ @default_input) + def solve(""), do: {:error, :no_input} + + def solve(input_file) when is_binary(input_file) and input_file != "" do + case File.read(input_file) do + {:ok, content} -> solve_content(content) + {:error, reason} -> {:error, reason} + end + end + + @doc """ + Solve part 2 of the challenge + """ + def solve_part2(input_file \\ @default_input) + def solve_part2(""), do: {:error, :no_input} + + def solve_part2(input_file) when is_binary(input_file) and input_file != "" do + case File.read(input_file) do + {:ok, content} -> solve_part2_content(content) + {:error, reason} -> {:error, reason} + end + end + + # Private functions + + defp solve_content(""), do: {:error, :no_input} + + defp solve_content(content) when is_binary(content) and content != "" do + result = + content + |> parse_input() + + {:ok, result} + end + + defp solve_part2_content(""), do: {:error, :no_input} + + defp solve_part2_content(content) when is_binary(content) and content != "" do + result = + content + |> parse_input() + + {:ok, result} + end + + defp parse_input(input) do + input + |> String.split("\n", trim: true) + end +end diff --git a/priv/inputs/day05/input.txt b/priv/inputs/day05/input.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/priv/inputs/day05/input.txt @@ -0,0 +1 @@ +