From 4e58ab46ebae2933340971fd5fe8b906240fa7a4 Mon Sep 17 00:00:00 2001 From: shu Date: Sun, 1 Dec 2019 09:02:57 +0100 Subject: [PATCH] day1 --- 2019/day1/day1.hs | 14 +++++++ 2019/day1/input | 100 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 2019/day1/day1.hs create mode 100644 2019/day1/input diff --git a/2019/day1/day1.hs b/2019/day1/day1.hs new file mode 100644 index 0000000..e6cfd87 --- /dev/null +++ b/2019/day1/day1.hs @@ -0,0 +1,14 @@ +main = do + content <- readFile "input" + let input = lines content + print (day11 input) + print (day12 input) + + +day11 :: [String] -> Int +day11 xs = sum $ map ((subtract 2) . floor . (/ 3) . read) xs + +day12 :: [String] -> Int +day12 xs = (sum $ map (f . read) xs) - (sum $ map read xs) where + f x | x>0=x+f (((subtract 2) . floor . (/ 3) . fromIntegral) x) + | otherwise = 0 diff --git a/2019/day1/input b/2019/day1/input new file mode 100644 index 0000000..71e5f95 --- /dev/null +++ b/2019/day1/input @@ -0,0 +1,100 @@ +50962 +126857 +127476 +136169 +62054 +116866 +123235 +147126 +146767 +140795 +54110 +106452 +98413 +114925 +141914 +54864 +120093 +118166 +81996 +143924 +145941 +96950 +126488 +85764 +111438 +63278 +147558 +128982 +123857 +58646 +80757 +98260 +97143 +136609 +99349 +63167 +142129 +144645 +97212 +70162 +98044 +125931 +103859 +67890 +67797 +79263 +134255 +130303 +73367 +103091 +97315 +74892 +82311 +51157 +79802 +138401 +108423 +63111 +61441 +102862 +53184 +125543 +147413 +117762 +106771 +115805 +66424 +85851 +53101 +82736 +136768 +130745 +140135 +101770 +55349 +143419 +60108 +84990 +91544 +75240 +92709 +134369 +140901 +59910 +63641 +54966 +104671 +71950 +60358 +127289 +147362 +70799 +82870 +108630 +53450 +106888 +129843 +53227 +58758 +137751