Haskell
module Main where import Data.List (sort, sortOn) import Data.Ord (Down(Down)) import Control.Arrow ((&&&)) interactLn :: (String -> String) -> IO () interactLn f = interact f *> putStrLn "" main :: IO () main = interactLn $ show . (part1 &&& part2) . nubCount . sort . map read . init . lines mkPart f = product . map snd . take 3 . sortOn f part1, part2 :: [(Int, Int)] -> Int part1 = mkPart Down part2 = mkPart id nubCount :: Eq a => [a] -> [(Int, a)] nubCount = go . map (1,) where go [] = [] go [x] = [x] go ((nx, x):(ny, y):rest) | x == y = go $ (nx+ny, x):rest | otherwise = (nx, x) : go ((ny, y):rest)
Apparently, my part 2 is wrong? I double-checked with a second solution from here but it’s the same result. I’d like to ask for help, but since I’m not allowed to share my input I’m a bit at a loss.