In [1]:
inputLines = lines <$> readFile "input/day1.txt"
In [2]:
fuelRequired1 :: Int -> Int
fuelRequired1 mass = (mass `div` 3) - 2
In [3]:
fuelRequired1 12 == 2 && fuelRequired1 14 == 2 && fuelRequired1 1969 == 654 && fuelRequired1 100756 == 33583
In [4]:
sum <$> map (fuelRequired1 . read) <$> inputLines
In [5]:
fuelRequired2 :: Int -> Int
fuelRequired2 mass
| fuel <= 0 = 0
| otherwise = fuel + fuelRequired2 fuel
where fuel = fuelRequired1 mass
In [6]:
fuelRequired2 14 == 2 && fuelRequired2 1969 == 966 && fuelRequired2 100756 == 50346
In [7]:
sum <$> map (fuelRequired2 .read) <$> inputLines
In [8]:
sum . map (sum . takeWhile (>=0) . tail . iterate fuelRequired1 . read) <$> inputLines