AdventOfCode-2019/day1.hs

16 lines
298 B
Haskell
Raw Permalink Normal View History

2020-11-30 22:16:06 -08:00
cost :: Int -> Int
cost x = (x `div` 3) - 2
fuel :: Int -> [Int]
fuel x
| cost x <= 0 = []
| otherwise = cost x : fuel (cost x)
totalCost :: Int -> Int
totalCost = sum . fuel
main :: IO ()
main = do
ls <- map read <$> lines <$> readFile "day1.txt"
print $ sum $ map totalCost ls