From b338b3c2caf072b0357662a321408bcca7407bb7 Mon Sep 17 00:00:00 2001 From: Arranun Date: Thu, 5 Dec 2019 08:29:13 +0100 Subject: [PATCH] day1 --- day1.hs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 day1.hs diff --git a/day1.hs b/day1.hs new file mode 100644 index 0000000..711b493 --- /dev/null +++ b/day1.hs @@ -0,0 +1,17 @@ + +main = do + content <- getContents + putStrLn (show $ foldl getOp 0 (lines content)) + +getOp :: Int -> String -> Int +getOp acc number = acc + (math (read number)) + getFuel 0 (math(read number)) + +getFuel :: Int -> Int -> Int +getFuel acc fuel = do + if (math fuel) > 0 + then acc + (math fuel) + getFuel acc (math fuel) + else + acc + +math :: Int -> Int +math input = ((input `div` 3) - 2)