From 35f82a2aed37c8daf523ac4c9fbf7112659e8dda Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sun, 1 Dec 2019 09:42:09 +0100 Subject: Start 2019! --- 2019/1.hs | 13 ++++++++ 2019/1.in | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2019/Input.hs | 20 ++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 2019/1.hs create mode 100644 2019/1.in create mode 100644 2019/Input.hs diff --git a/2019/1.hs b/2019/1.hs new file mode 100644 index 0000000..a3b86f1 --- /dev/null +++ b/2019/1.hs @@ -0,0 +1,13 @@ +module Main where + +import Input + + +main :: IO () +main = do + input <- map read <$> getInput 1 :: IO [Int] + print (sum [n `div` 3 - 2 | n <- input]) + + let compute f = let extra = f `div` 3 - 2 + in if extra <= 0 then 0 else extra + compute extra + print (sum (map compute input)) diff --git a/2019/1.in b/2019/1.in new file mode 100644 index 0000000..3d7053c --- /dev/null +++ b/2019/1.in @@ -0,0 +1,100 @@ +92903 +97793 +95910 +104540 +122569 +60424 +145155 +90081 +81893 +140366 +77358 +122977 +114868 +135274 +80770 +104328 +87475 +135948 +128585 +71353 +93571 +69870 +137262 +142606 +95397 +62517 +87269 +73336 +118502 +82894 +125097 +102311 +134164 +119828 +116181 +99303 +88937 +63418 +145060 +91014 +136031 +106000 +105084 +139280 +99775 +94626 +99081 +119824 +58232 +54759 +93633 +142621 +63718 +106439 +62425 +119965 +73033 +130019 +93223 +118848 +122769 +130704 +63418 +87205 +137230 +147960 +51051 +65279 +82183 +57705 +102519 +144031 +94413 +98485 +130646 +111400 +100503 +95963 +143785 +97857 +146611 +67684 +79662 +147350 +60427 +118683 +128729 +65014 +55844 +120846 +117969 +134494 +127003 +139614 +95021 +124970 +100680 +91622 +106898 +79702 diff --git a/2019/Input.hs b/2019/Input.hs new file mode 100644 index 0000000..afce44e --- /dev/null +++ b/2019/Input.hs @@ -0,0 +1,20 @@ +module Input where + +import System.Environment +import System.IO + + +getInput :: Int -> IO [String] +getInput day = do + let fname = show day ++ ".in" + + args <- getArgs + str <- case args of + ["-"] -> getContents + [] -> readFile fname + _ -> do + hPutStrLn stderr $ "WARNING: Unrecognised command-line parameters " ++ show args ++ + ", reading from " ++ fname + readFile fname + + return (lines str) -- cgit v1.2.3-70-g09d2