19 lines
707 B
Haskell
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
|