diff options
author | Julien Dessaux | 2023-03-13 21:36:59 +0100 |
---|---|---|
committer | Julien Dessaux | 2023-03-13 21:36:59 +0100 |
commit | 9c4275d2181f72aa672e3c8cbe2336eb34c19a25 (patch) | |
tree | b45382b88080c82daf9512a131ee29bc810c81f4 /2020/06-Custom_Customs/first.hs | |
parent | 2020-05 in haskell (diff) | |
download | advent-of-code-9c4275d2181f72aa672e3c8cbe2336eb34c19a25.tar.gz advent-of-code-9c4275d2181f72aa672e3c8cbe2336eb34c19a25.tar.bz2 advent-of-code-9c4275d2181f72aa672e3c8cbe2336eb34c19a25.zip |
2020-06 in haskell
Diffstat (limited to '2020/06-Custom_Customs/first.hs')
-rw-r--r-- | 2020/06-Custom_Customs/first.hs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/2020/06-Custom_Customs/first.hs b/2020/06-Custom_Customs/first.hs new file mode 100644 index 0000000..883d6e4 --- /dev/null +++ b/2020/06-Custom_Customs/first.hs @@ -0,0 +1,26 @@ +-- requires cabal install --lib split Unique +module Main (main) where + +import Control.Monad (void, when) +import Data.List.Split (splitOn) +import Data.List.Unique (sortUniq) +import Data.Monoid (mconcat) +import System.Exit (die) + +exampleExpectedOutput = 11 + +parseInput :: String -> IO [String] +parseInput filename = do + input <- readFile filename + return $ map (sortUniq . mconcat . lines) $ splitOn "\n\n" input + +compute :: [String] -> Int +compute = sum . map length + +main :: IO () +main = do + example <- parseInput "example" + let exampleOutput = compute example + when (exampleOutput /= exampleExpectedOutput) (die $ "example failed: got " ++ show exampleOutput ++ " instead of " ++ show exampleExpectedOutput) + input <- parseInput "input" + print $ compute input |