From b3a07a5c0fd62f37c4d8e43031d1bbd245f65b67 Mon Sep 17 00:00:00 2001 From: Sloane Perrault Date: Wed, 21 Sep 2022 09:19:53 -0400 Subject: [PATCH] feat: pad numbers --- 2021/lib/advent_of_code.ex | 15 ++++++++++++--- 2021/lib/advent_of_code/day0.ex | 0 2021/lib/advent_of_code/day0/part0.ex | 11 ----------- 2021/lib/mix/advent_of_code.ex | 9 ++------- 2021/priv/inputs/0.0.input | 3 --- 2021/test/advent_of_code/day0/part_0_test.exs | 7 ------- 2021/test/advent_of_code_test.exs | 14 +++++++++++--- 7 files changed, 25 insertions(+), 34 deletions(-) delete mode 100644 2021/lib/advent_of_code/day0.ex delete mode 100644 2021/lib/advent_of_code/day0/part0.ex delete mode 100644 2021/priv/inputs/0.0.input delete mode 100644 2021/test/advent_of_code/day0/part_0_test.exs diff --git a/2021/lib/advent_of_code.ex b/2021/lib/advent_of_code.ex index f8016fb..42478ec 100644 --- a/2021/lib/advent_of_code.ex +++ b/2021/lib/advent_of_code.ex @@ -5,8 +5,17 @@ defmodule AdventOfCode do def solver(selector) do [day, part] = String.split(selector, ".") - day_module = Macro.camelize("Day#{day}") - part_module = Macro.camelize("Part#{part}") - Module.concat([AdventOfCode, day_module, part_module]) + part_module(day, part) end + + def part_module(day, part) do + Module.concat(day_module(day), Macro.camelize("Part#{part_number(part)}")) + end + + def day_module(day) do + Module.concat(AdventOfCode, Macro.camelize("Day#{day_number(day)}")) + end + + defp day_number(day), do: String.pad_leading(day, 2, "0") + defp part_number(part), do: String.trim_leading(part, "0") end diff --git a/2021/lib/advent_of_code/day0.ex b/2021/lib/advent_of_code/day0.ex deleted file mode 100644 index e69de29..0000000 diff --git a/2021/lib/advent_of_code/day0/part0.ex b/2021/lib/advent_of_code/day0/part0.ex deleted file mode 100644 index 6c32387..0000000 --- a/2021/lib/advent_of_code/day0/part0.ex +++ /dev/null @@ -1,11 +0,0 @@ -defmodule AdventOfCode.Day0.Part0 do - alias AdventOfCode.PuzzleSolver - - use PuzzleSolver - - @impl PuzzleSolver - def solve(stream) do - Stream.run(stream) - "42" - end -end diff --git a/2021/lib/mix/advent_of_code.ex b/2021/lib/mix/advent_of_code.ex index a012629..8e8cd91 100644 --- a/2021/lib/mix/advent_of_code.ex +++ b/2021/lib/mix/advent_of_code.ex @@ -3,11 +3,6 @@ defmodule Mix.AdventOfCode do Helpers for `AdventOfCode` mix tasks. """ - def day_module(day) do - Module.concat(AdventOfCode, Macro.camelize("Day#{day}")) - end - - def part_module(day, part) do - Module.concat(day_module(day), Macro.camelize("Part#{part}")) - end + defdelegate day_module(day), to: AdventOfCode + defdelegate part_module(day, part), to: AdventOfCode end diff --git a/2021/priv/inputs/0.0.input b/2021/priv/inputs/0.0.input deleted file mode 100644 index 86e041d..0000000 --- a/2021/priv/inputs/0.0.input +++ /dev/null @@ -1,3 +0,0 @@ -foo -bar -baz diff --git a/2021/test/advent_of_code/day0/part_0_test.exs b/2021/test/advent_of_code/day0/part_0_test.exs deleted file mode 100644 index cd53141..0000000 --- a/2021/test/advent_of_code/day0/part_0_test.exs +++ /dev/null @@ -1,7 +0,0 @@ -defmodule AdventOfCode.Day0.Part0Test do - use AdventOfCode.PuzzleCase, module: AdventOfCode.Day0.Part0 - - test "returns the answer to live the universe and everything" do - assert_solution "life the universe and everything", "42" - end -end diff --git a/2021/test/advent_of_code_test.exs b/2021/test/advent_of_code_test.exs index 589fa60..e9a64bb 100644 --- a/2021/test/advent_of_code_test.exs +++ b/2021/test/advent_of_code_test.exs @@ -5,9 +5,17 @@ defmodule AdventOfCodeTest do describe "solver/1" do test "returns a module for a solver" do - assert solver("1.1") == AdventOfCode.Day1.Part1 - assert solver("2.2") == AdventOfCode.Day2.Part2 - assert solver("3.1") == AdventOfCode.Day3.Part1 + assert solver("1.1") == AdventOfCode.Day01.Part1 + assert solver("2.2") == AdventOfCode.Day02.Part2 + assert solver("3.1") == AdventOfCode.Day03.Part1 + end + + test "returns a solver module for zero padded numbers" do + assert solver("01.01") == AdventOfCode.Day01.Part1 + assert solver("02.2") == AdventOfCode.Day02.Part2 + assert solver("3.01") == AdventOfCode.Day03.Part1 + assert solver("12.1") == AdventOfCode.Day12.Part1 + assert solver("24.02") == AdventOfCode.Day24.Part2 end end end