From 5dfb41306eb1189d6da55081e0d9f41d80c3e215 Mon Sep 17 00:00:00 2001 From: Samuel Owen Date: Wed, 27 Dec 2023 22:22:39 +0000 Subject: [PATCH] Add validate_set function to check if the sum of cube amounts exceeds the limit --- lib/day2/day2.ex | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/day2/day2.ex b/lib/day2/day2.ex index f31c1a0..6bdf245 100644 --- a/lib/day2/day2.ex +++ b/lib/day2/day2.ex @@ -59,4 +59,13 @@ defmodule Day2 do def sum_map(map) do Map.values(map) |> Enum.sum() end + + def validate_set(game_set_string, cube_limit) do + cube_map = parse_game_set_amounts(game_set_string) + + case sum_map(cube_map) > cube_limit do + true -> false + false -> true + end + end end