Skip to content

Commit

Permalink
Add day 1 and day 2 solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
samjowen committed Dec 27, 2023
1 parent 8a12387 commit 71b9172
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/advent_of_code2023.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule AdventOfCode2023 do
Documentation for `AdventOfCode2023`.
"""

# Day 1
def day1_solve_part_1(input_file_path) do
Day1.parse_file(input_file_path)
|> Enum.map(&Day1.combine_first_and_last_number/1)
Expand All @@ -15,4 +16,9 @@ defmodule AdventOfCode2023 do
|> Enum.map(&Day1.combine_first_and_last_number/1)
|> Enum.sum()
end

# Day 2
def day2_solve_part2(input_file_path) do
Day1.parse_file(input_file_path)
end
end
12 changes: 12 additions & 0 deletions test/day2/day2_solves_tests.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule Day2SolvesTest do
@moduledoc """
This module contains tests for the Day2 module.
"""

use ExUnit.Case
doctest AdventOfCode2023

test "solves the day 2 part II puzzle correctly" do
assert AdventOfCode2023.day2_solve_part_2("./test/day2/mocks/part2-test-case.txt") == 8
end
end
5 changes: 5 additions & 0 deletions test/day2/mocks/part-2-test-case.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green

0 comments on commit 71b9172

Please sign in to comment.