Initial commit with Day 1, 2 and part of 3

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2019-12-03 17:57:43 -05:00
commit a2297e765a
5 changed files with 486 additions and 0 deletions

22
day01/Day01.hs Normal file
View File

@@ -0,0 +1,22 @@
main :: IO()
main = do
inputText <- getContents
let inputValues = map read (lines inputText)
putStr "Part 1: "
putStrLn $ show (part1 inputValues)
putStr "Part 2: "
putStrLn $ show (part2 inputValues)
part1 :: [Int] -> Int
part1 numbers = sum $ map fuelReq numbers
fuelReq :: Int -> Int
fuelReq mass = max 0 ((mass `div` 3) - 2)
part2 :: [Int] -> Int
part2 numbers = sum $ map fullFuelReq numbers
fullFuelReq :: Int -> Int
fullFuelReq mass =
if fuelReq mass == 0 then 0
else (fuelReq mass) + (fullFuelReq $ fuelReq mass)