Broke days into individual pacakges
[advent-of-code-16.git] / adventofcode1606 / app / advent06.hs
diff --git a/adventofcode1606/app/advent06.hs b/adventofcode1606/app/advent06.hs
new file mode 100644 (file)
index 0000000..96c4aa2
--- /dev/null
@@ -0,0 +1,22 @@
+module Main(main) where
+
+import Data.List (transpose, maximum, minimum, sort, group)
+import Data.Tuple (swap)
+
+main :: IO ()
+main = do 
+    text <- readFile "data/advent06.txt" 
+    let message = lines text
+    part1 message
+    part2 message
+
+part1 :: [String] -> IO ()
+part1 message = do 
+    putStrLn $ map (snd . maximum . counts) $ transpose message
+
+part2 :: [String] -> IO ()
+part2 message = do 
+    putStrLn $ map (snd . minimum . counts) $ transpose message
+
+counts :: (Eq a, Ord a) => [a] -> [(Int, a)]
+counts = map (\g -> (length g, head g)) . group . sort
\ No newline at end of file