ロケット方程式の圧制
コード2019日1の出現
タスク:Xのどこに解決する.
X = the sum of the fuel requirements
例入力
12
14
1969
100756
It represents:第1部
私の作業アルゴリズムの記述
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
私の作業アルゴリズムの視覚的描写
第2部
私の作業アルゴリズムの記述
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
私の作業アルゴリズムの視覚的描写
削減再帰次のいずれかの準備.
Reference
この問題について(ロケット方程式の圧制), 我々は、より多くの情報をここで見つけました https://dev.to/rmion/the-tyranny-of-the-rocket-equation-32naテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol