Created
December 13, 2019 08:54
-
-
Save Pranz/4bdc6d7d1403918da11ac0b2d5fd0c0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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