Rocket science


#1

Discussion thread for Problem 1: Rocket science.


#2

I cannot seem to be able to pass this problem. Please note that I am a very beginner but even so, I pass for most planets except for Jupiter. At first I only passed the problem for one planet but after I added more decimals to Euler’s number, I am passing the test for 5 out of 6 planets.

This is the code I am using:

function rocket_fuel(v) {
 
const v_e = 2550;  // rocket exhaust velocity [m/s]
const M = 250000;  // rocket dry mass [kg]
const e = 2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274274663919320030599218174135966290435729003342952605956307381323286279434907; // Euler's number
let m_fuel = 0.0;

m_fuel = M * (Math.pow(e, v / v_e ) - 1); 

return m_fuel;
}

rocket_fuel(11186);

Might be a bug?


#3

Thanks so much for bringing this up.

I tested out your code and this is definitely a bug on our side. The problem is in how we are checking solutions. Basically, we need to increase the “error margin” for the solution for your code so it passes, because your code looks good to me.

Here’s a workaround for you: instead of using Math.pow(e, …), use Math.exp(…).

If you read online about Math.exp() you’ll find that it’s basically just Math.pow but the first parameter (the base) is always set to Euler’s number e.


#4

Yes, that seems to be alright. It is working now.


#5

Just fixed the error/tolerance checking so the first 6 digits need to be correct instead of the first 3 decimal places (which is what we were doing). @WaterlooPitt just tried it and your original code should work now! Thanks for letting us know, other people were probably having the same issue as well.