aoc-2019-c

Advent of Code 2019 Solutions in C
git clone https://git.sinitax.com/sinitax/aoc-2019-c
Log | Files | Refs | README | sfeed.txt

part2 (1827B)


      1--- Part Two ---
      2
      3During the second Go / No Go poll, the Elf in charge of the Rocket Equation Double-Checker stops the
      4launch sequence.  Apparently, you forgot to include additional fuel for the fuel you just added.
      5
      6Fuel itself requires fuel just like a module - take its mass, divide by three, round down, and
      7subtract 2.  However, that fuel also requires fuel, and that fuel requires fuel, and so on.  Any
      8mass that would require negative fuel should instead be treated as if it requires zero fuel; the
      9remaining mass, if any, is instead handled by wishing really hard, which has no mass and is outside
     10the scope of this calculation.
     11
     12So, for each module mass, calculate its fuel and add it to the total.  Then, treat the fuel amount
     13you just calculated as the input mass and repeat the process, continuing until a fuel requirement is
     14zero or negative. For example:
     15
     16
     17 - A module of mass 14 requires 2 fuel.  This fuel requires no further fuel (2 divided by 3 and
     18rounded down is 0, which would call for a negative fuel), so the total fuel required is still just
     192.
     20
     21 - At first, a module of mass 1969 requires 654 fuel.  Then, this fuel requires 216 more fuel (654 /
     223 - 2).  216 then requires 70 more fuel, which requires 21 fuel, which requires 5 fuel, which
     23requires no further fuel.  So, the total fuel required for a module of mass 1969 is 654 + 216 + 70 +
     2421 + 5 = 966.
     25
     26 - The fuel required by a module of mass 100756 and its fuel is: 33583 + 11192 + 3728 + 1240 + 411 +
     27135 + 43 + 12 + 2 = 50346.
     28
     29
     30What is the sum of the fuel requirements for all of the modules on your spacecraft when also taking
     31into account the mass of the added fuel? (Calculate the fuel requirements for each module
     32separately, then add them all up at the end.)
     33
     34