From 2096e9f64717e752f4fe769a565128a5d6d5ab8a Mon Sep 17 00:00:00 2001 From: Samuel Owen Date: Sun, 24 Dec 2023 02:13:03 +0000 Subject: [PATCH] Refactor parse_game_number and add parse_game_sets --- lib/day2/day2.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/day2/day2.ex b/lib/day2/day2.ex index 24bb780..2d4597c 100644 --- a/lib/day2/day2.ex +++ b/lib/day2/day2.ex @@ -6,6 +6,13 @@ defmodule Day2 do def parse_game_number(game_string) do String.split(game_string, " ", trim: true) |> Enum.take(2) - |> List.last() |> String.replace(":", "") + |> List.last() + |> String.replace(":", "") + end + + def parse_game_sets(game_string) do + Regex.replace(~r/\bGame (\d+):\s/, game_string, "") + |> String.split(";") + |> Enum.map(&String.trim/1) end end