16 lines
298 B
Haskell
16 lines
298 B
Haskell
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
|