diff options
author | Julien Dessaux | 2023-03-09 21:55:36 +0100 |
---|---|---|
committer | Julien Dessaux | 2023-03-09 21:55:36 +0100 |
commit | 316a48b6a87bffce372ef2186ace9f0565c3eceb (patch) | |
tree | 483fd10d657f5977dd1b84e1fea11bfdfb24801c /2020/01/first.hs | |
parent | 2020-02 in haskell (diff) | |
download | advent-of-code-316a48b6a87bffce372ef2186ace9f0565c3eceb.tar.gz advent-of-code-316a48b6a87bffce372ef2186ace9f0565c3eceb.tar.bz2 advent-of-code-316a48b6a87bffce372ef2186ace9f0565c3eceb.zip |
Renamed folder
Diffstat (limited to '2020/01/first.hs')
-rw-r--r-- | 2020/01/first.hs | 29 |
1 files changed, 0 insertions, 29 deletions
diff --git a/2020/01/first.hs b/2020/01/first.hs deleted file mode 100644 index 5a615a9..0000000 --- a/2020/01/first.hs +++ /dev/null @@ -1,29 +0,0 @@ -module Main where - -import Control.Monad (when) -import Data.Maybe (catMaybes, fromJust) -import System.Exit (die) - -exampleExpectedOutput = 514579 - -compute2020 :: Int -> Int -> Maybe Int -compute2020 a b - | a + b == 2020 = Just (a * b) - | otherwise = Nothing - -compute :: String -> Int -compute input = head . catMaybes $ processInput inputList - where - inputList :: [Int] - inputList = map read $ lines input - processInput :: [Int] -> [Maybe Int] - processInput (_:[]) = [Nothing] - processInput (x:xs) = map (compute2020 x) xs ++ processInput xs - -main :: IO () -main = do - example <- readFile "example" - let exampleOutput = compute example - when (exampleOutput /= exampleExpectedOutput) (die $ "example failed: got " ++ show exampleOutput ++ " instead of " ++ show exampleExpectedOutput) - input <- readFile "input" - print $ compute input |