## DEV Community # The Tyranny of the Rocket Equation

## Task: Solve for X where...

``````X = the sum of the fuel requirements
``````

### Example input

``````12
14
1969
100756
``````

It represents:

• The mass each module

## Part 1

### A written description of my working algorithm

``````Split the input at each newline character to generate an array of strings
Coerce each string to a number
For each number, accumulate a number - starting at 0
Add to the accumulating number the sum of that number and the current number divided by 3, rounded down, and decremented by 2
Return the accumulated number
``````

### A visual depiction of my working algorithm ## Part 2

### A written description of my working algorithm

``````Sub-routine: Recursive Fuel
- Accept a number as input
If the number is less than or equal to 0
Return 0
Else
Return the sum of the input number and the number returned from calling this sub-routine with the number resulting from dividing the input number by 3, rounding down, and decrementing by 2

Split the input at each newline character to generate an array of strings
Coerce each string to a number
For each number, accumulate a number - starting at 0
Add to the accumulating number the number returned from calling Recursive Fuel with the number resulting from dividing the current number by 3, rounding down, and decrementing by 2
Return the accumulated number
``````

### A visual depiction of my working algorithm Reduction. Recursion. Ready for the next one.