Files
advent-of-code-2023/day02/Part2.hs
2023-12-04 19:05:20 +01:00

19 lines
707 B
Haskell

module Part2 where
import Commons
import Data.Function (on)
getMinCubesRound :: [Round] -> Round
getMinCubesRound [round] = round
getMinCubesRound (round: otherRound: t) = getMinCubesRound $ Round {red = (max `on` red) round otherRound,
green = (max `on` green) round otherRound,
blue = (max `on` blue) round otherRound}: t
getPowerGame :: Game -> Int
getPowerGame Game{rounds=rounds} = let minRound = getMinCubesRound rounds
in red minRound * green minRound * blue minRound
getPower :: [Game] -> [Int]
getPower = map getPowerGame