Files
adventofcode-2019/day01/Day01.hs

23 lines
557 B
Haskell
Raw Normal View History

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)