Skip to content

Instantly share code, notes, and snippets.

@wcarroll
Last active December 1, 2019 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wcarroll/f42deb2dd8b0882768c4351b4aeca40c to your computer and use it in GitHub Desktop.
Save wcarroll/f42deb2dd8b0882768c4351b4aeca40c to your computer and use it in GitHub Desktop.
Advent of Code 2019 - Day 1 - Problem 2 Solution
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