feat: day 2 part 2

This commit is contained in:
Fernando Araoz 2024-11-11 14:03:54 -05:00
parent 90fe696ca4
commit 1c7d4d92be

View File

@ -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)))