From f04914844da58e34220e4c4e67131cb7435de49f Mon Sep 17 00:00:00 2001 From: Samuel Owen Date: Sun, 24 Dec 2023 01:51:05 +0000 Subject: [PATCH] Add Day2 module with parse_game_number function --- lib/day2/day2.ex | 11 +++++++++++ test/day2/day2_test.exs | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 lib/day2/day2.ex diff --git a/lib/day2/day2.ex b/lib/day2/day2.ex new file mode 100644 index 0000000..24bb780 --- /dev/null +++ b/lib/day2/day2.ex @@ -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 diff --git a/test/day2/day2_test.exs b/test/day2/day2_test.exs index cdf1ce2..5dcc32d 100644 --- a/test/day2/day2_test.exs +++ b/test/day2/day2_test.exs @@ -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