summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2019/1.hs13
-rw-r--r--2019/1.in100
-rw-r--r--2019/Input.hs20
3 files changed, 133 insertions, 0 deletions
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)