Last active
December 1, 2019 23:55
-
-
Save wcarroll/f42deb2dd8b0882768c4351b4aeca40c to your computer and use it in GitHub Desktop.
Advent of Code 2019 - Day 1 - Problem 2 Solution
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
Function Get-Fuel ($PayloadMass) { | |
$RequiredFuel = [Math]::Floor($PayloadMass / 3) - 2 | |
if ($RequiredFuel -le 0) { | |
return 0 | |
} else { | |
return $($RequiredFuel + $(Get-Fuel($RequiredFuel))) | |
} | |
} | |
$PayloadMasses = Get-Content .\PayloadMasses.txt | |
$TotalRequiredFuel = 0 | |
foreach ($PayloadMass in $PayloadMasses) { | |
$TotalRequiredFuel += Get-Fuel($PayloadMass) | |
} | |
Write-Output "Total Required Fuel: $TotalRequiredFuel" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment