Skip to content

Commit

Permalink
Add Day2 module with parse_game_number function
Browse files Browse the repository at this point in the history
  • Loading branch information
samjowen committed Dec 24, 2023
1 parent dd68469 commit f049148
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lib/day2/day2.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule Day2 do
@moduledoc """
Documentation for `AdventOfCode2023`.
"""

def parse_game_number(game_string) do
String.split(game_string, " ", trim: true)
|> Enum.take(2)
|> List.last() |> String.replace(":", "")
end
end
4 changes: 2 additions & 2 deletions test/day2/day2_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Day2Test do
"Game 1: 7 red, 14 blue; 2 blue, 3 red, 3 green; 4 green, 12 blue, 15 red; 3 green, 12 blue, 3 red; 11 red, 2 green"

large_game_string = "Game 999: 8 red"
assert AdventOfCode2023.get_game_string(game_string) == 1
assert AdventOfCode2023.get_game_string(large_game_string) == 999
assert Day2.parse_game_number(game_string) == "1"
assert Day2.parse_game_number(large_game_string) == "999"
end
end

0 comments on commit f049148

Please sign in to comment.