Skip to content

Instantly share code, notes, and snippets.

@Pranz
Created December 13, 2019 08:54
Show Gist options
  • Save Pranz/4bdc6d7d1403918da11ac0b2d5fd0c0f to your computer and use it in GitHub Desktop.
Save Pranz/4bdc6d7d1403918da11ac0b2d5fd0c0f to your computer and use it in GitHub Desktop.
main :: IO ()
main = do
part2_test
part2
part1 :: IO ()
part1 = do
input <- readFile "./aoc1_input"
let masses = map read . lines $ input
let fuel = map fuelRequired masses
let totalFuel = sum fuel
print totalFuel
part2 :: IO ()
part2 = do
input <- readFile "./aoc1_input"
let masses = map read . lines $ input
let fuel = map fuelRequiredIterative masses
let totalFuel = sum fuel
print totalFuel
fuelRequired :: Int -> Int
fuelRequired = (max 0) . (subtract 2) . (`div` 3)
fuelRequiredIterative :: Int -> Int
fuelRequiredIterative = sum . tail . takeWhile (/= 0) . iterate fuelRequired
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment