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