You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

15 lines
298 B

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