2020-06 in haskell
This commit is contained in:
parent
83849a30ae
commit
9c4275d218
4 changed files with 2245 additions and 0 deletions
15
2020/06-Custom_Customs/example
Normal file
15
2020/06-Custom_Customs/example
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
abc
|
||||||
|
|
||||||
|
a
|
||||||
|
b
|
||||||
|
c
|
||||||
|
|
||||||
|
ab
|
||||||
|
ac
|
||||||
|
|
||||||
|
a
|
||||||
|
a
|
||||||
|
a
|
||||||
|
a
|
||||||
|
|
||||||
|
b
|
26
2020/06-Custom_Customs/first.hs
Normal file
26
2020/06-Custom_Customs/first.hs
Normal file
|
@ -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
|
2179
2020/06-Custom_Customs/input
Normal file
2179
2020/06-Custom_Customs/input
Normal file
File diff suppressed because it is too large
Load diff
25
2020/06-Custom_Customs/second.hs
Normal file
25
2020/06-Custom_Customs/second.hs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
-- requires cabal install --lib split Unique
|
||||||
|
module Main (main) where
|
||||||
|
|
||||||
|
import Control.Monad (void, when)
|
||||||
|
import Data.List (intersect, foldl')
|
||||||
|
import Data.List.Split (splitOn)
|
||||||
|
import System.Exit (die)
|
||||||
|
|
||||||
|
exampleExpectedOutput = 6
|
||||||
|
|
||||||
|
parseInput :: String -> IO [String]
|
||||||
|
parseInput filename = do
|
||||||
|
input <- readFile filename
|
||||||
|
return $ map (foldl' intersect ['a'..'z'] . 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
|
Loading…
Add table
Reference in a new issue