Example 1
Input: 11186.0
Output: 19843016.2
Rocket science
You will learn about: submitting code, rocket equation.
Moving stuff to outer space is super expensive and takes a lot of energy, which is part of the reason why colonizing the moon or terraforming Mars is extremely hard. To move something heavy into space you need a rocket with enough fuel. But adding fuel makes the rocket even heavier... And if you wanted to visit Mars and come back, you would need enough fuel to leave both Earth and Mars.
We can actually calculate how much fuel a rocket needs using the rocket equation: $m_\mathrm{fuel} = M \left( e^{v/v_e} - 1\right)$ where $M$ is the mass of the rocket (with no fuel), $v_e$ is the exhaust velocity of the rocket, and $e = 2.71828\dots$ is Euler's number. $v$ is the velocity the rocket needs to escape, which is different for every planet. Try to submit some code with a function rocket_fuel(v) that returns $m_\mathrm{fuel}$ for Saturn V ($M = 250,000 \; \mathrm{kg}$, $v_e = 2,550 \; \mathrm{m/s}$) as a function of $v$.
Input: The velocity $v$ the rocket needs to reach to escape the planet in meters per second (m/s).
Output: The mass of fuel $m_\mathrm{fuel}$ needed by the rocket to escape the planet in kilograms (kg).
Difficulty | Timesink | ||
---|---|---|---|
Maximum runtime | 60 s | Max. memory usage | 250 MiB |
Function signature | rocket_fuel(escape_velocity) |
Write a function that accepts the input as function parameters and returns the correct output. Make sure to read the description above to produce the correct output in the correct format and use the correct function signature so we can run your code. A good first step is to try reproducing the example(s). Your code must not take longer than the maximum runtime to run and must not use more memory than the allowed limit.
You must be logged in to view your submissions.
Let us know what you think about this problem! Was it too hard? Difficult to understand? Also feel free to discuss the problem, ask questions, and post cool stuff on Discourse. You should be able see a discussion thread below. Feel free to post your solutions but if you do please organize and document your code well so others can learn from it.