Now using fromMaybe
[advent-of-code-16.git] / advent06.hs
1 module Main(main) where
2
3 import Data.List (transpose, maximum, minimum, sort, group)
4 import Data.Tuple (swap)
5
6 main :: IO ()
7 main = do
8 text <- readFile "advent06.txt"
9 let message = lines text
10 part1 message
11 part2 message
12
13 part1 :: [String] -> IO ()
14 part1 message = do
15 putStrLn $ map (snd . maximum . counts) $ transpose message
16
17 part2 :: [String] -> IO ()
18 part2 message = do
19 putStrLn $ map (snd . minimum . counts) $ transpose message
20
21 counts :: (Eq a, Ord a) => [a] -> [(Int, a)]
22 counts = map (\g -> (length g, head g)) . group . sort