this repo has no description
1module Lib where
2
3fuelNeeded :: [String] -> Int
4fuelNeeded = sum . map (addRemainingFuel . fuelFromMass) . map (\w -> read w :: Int)
5
6fuelFromMass :: Int -> Int
7fuelFromMass x = (x `div` 3) - 2
8
9addRemainingFuel :: Int -> Int
10addRemainingFuel x = sum $ go [x] x
11 where go :: [Int] -> Int -> [Int]
12 go xs x'
13 | fuelFromMass x' > 0 = go (xs ++ [fuelFromMass x']) $ fuelFromMass x'
14 | otherwise = xs