1 import qualified Data.Map as M
7 let count_twos = countN 2 ids
8 let count_threes = countN 3 ids
9 print (count_twos * count_threes)
12 countN :: Int -> [String] -> Int
13 countN check_count = sum . map (go check_count)
14 where go :: Int -> String -> Int
15 go cc test = if any (== cc) . M.elems . countChar $ test
19 countChar :: String -> M.Map Char Int
20 countChar = foldl go M.empty
21 where go :: M.Map Char Int -> Char -> M.Map Char Int
22 go chmap char = M.insert char ((M.findWithDefault 0 char chmap) + 1) chmap
24 abc :: [String] -> String
27 | otherwise = head test
28 where cor_len = (length i) - 1
29 test = filter (\s -> (length s) == cor_len) . map (diff i) $ is
31 diff :: Eq a => [a] -> [a] -> [a]
34 | a == b = (a : diff as bs)
35 | otherwise = diff as bs