You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
477 B

module Part2 where
import Data.Map qualified as Map
getValueCounts :: [Int] -> Map.Map Int Int
getValueCounts [] = Map.empty
getValueCounts (x : xs) =
let xsMap = getValueCounts xs
newCount = Map.findWithDefault 0 x xsMap + 1
in Map.insert x newCount xsMap
getSimilarityScore :: [Int] -> Map.Map Int Int -> Int
getSimilarityScore [] map = 0
getSimilarityScore (x : xs) map = xScore + getSimilarityScore xs map
where
xScore = x * Map.findWithDefault 0 x map