From 1c7d4d92be63363e04f0fbb2dd3ad869b865f606 Mon Sep 17 00:00:00 2001 From: Fernando Araoz Date: Mon, 11 Nov 2024 14:03:54 -0500 Subject: [PATCH] feat: day 2 part 2 --- src/day02.clj | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/day02.clj b/src/day02.clj index 7a1f7fc..1bebb76 100644 --- a/src/day02.clj +++ b/src/day02.clj @@ -77,8 +77,51 @@ possible-games-sum (reduce #(+ %1 (%2 :id)) 0 possible-games)] (str possible-games-sum))) +; +; +; what is the fewest number of cubes of each color that could have +; been in the bag to make the game possible? +; +; The power of a set of cubes is equal to the numbers of +; red, green, and blue cubes multiplied together +; For each game, find the minimum set of cubes that must have been present. +; What is the sum of the power of these sets? +; + +(defn games-minimum + ":: Vector of {:red Int :green Int :blue Int} -> {:red Int :green Int :blue Int}" + [games] + (reduce (fn [acc next-game] + (let [acc-red (acc :red) + acc-green (acc :green) + acc-blue (acc :blue) + + next-red (next-game :red 0) + next-blue (next-game :blue 0) + next-green (next-game :green 0) + + new-red (last (sort (list acc-red next-red))) + new-green (last (sort (list acc-green next-green))) + new-blue (last (sort (list acc-blue next-blue)))] + {:red new-red :green new-green :blue new-blue})) + {:red 0 :green 0 :blue 0} + games)) + +(defn get-power + ":: Game -> Int + + Returns the minimum value of each color in the game" + [game] + ; minimums :: Vector of {:red Int :green Int :blue Int} + (let [minimums (games-minimum (game :games))] + (* (minimums :red) (minimums :green) (minimums :blue)))) + (defn part2 ":: () -> String" [] - "") + (let [games (map parse-game lines) + powers (map get-power games) + sum (reduce + powers)] + (str sum))) +