I’ll discuss with you in private message.
When learning programming, it is useful to be able to what the program is doing in nontechnical terms. If you can put the existing code in a flow chart, then modify the flow chart to include how you want to approach the problem, that can help you think through the problem. If this is something you want to pursue, you can DM me and I can show you some resources.
Why only in private?
Why only in this puzzle thread?
There are more Ruby issues than Mars Lander-specific issues. I don’t want to flood this thread with discussion of the former ones.
Guys my C++ code is not doing what I want, can you help me understand why?
What I want: I want to go freefall and activate the thrusters full power just in time so that when we are around “v_speed = -1m/s” we are also touching ground.
What my code does: somehow the thrust sequence begins too soon, so when we hit v_speed = -1/ms we are actually ~85m from the ground… I don’t understand why…
Here’s my code:
[Mod edit: Please avoid posting codes on the forum.]
The statement says:
Please note that for each turn the value of the actual power is limited to the value of the previous turn +/- 1.
Your code outputs “0 4” once only, and that is not enough to switch power from 0 to 4. And subsequently you keep 1 as the power, so the lander keeps falling faster and faster.
By the way, please avoid posting codes on the forum. Please describe what your code does instead. Thanks.
I don’t think that’s the reason, because if you test the code you’ll notice that even if you output 4 at every turn like I do, their code in the background will clamp the increment to be just 1 higher than the power in the previous turn, so I choose to always output 4 for that reason.
If you look at the code executing will go through 0,1,2,3,4 power and then stay at 4, so nothing out of the ordinary there.
Where should I post the code then?
There is no way to figure this out if people don’t see my code.
If you look at the console output, you’ll see that the code you posted earlier outputs “0 4” only once (not “every turn” as you claim).
I’ve also mentioned that you should just describe what your code does instead of posting the code itself.
I’m sorry, you’re previous answer was probably correct and was my mistake because I’ve mistakenly shared an outdated version of the code, where indeed power was set only once, but it was fixed by the time I asked.
Still, there is no way to paste the code I actually wanted to show to ask for help?
Can’t you just describe what your code does?
the description in my first message was 100% accurate. It’s just I accompanied it with the wrong version of my code, confusing you in the process - sorry for that ^_^’
No worries
How do you determine when to “activate the thrusters full power just in time”? Could you describe in more detail what power your code outputs, and under what conditions you output a different power, and whether you increase/decrease it, etc?
Every turn it runs a “max_thrust_simulation(…variables…)” function - if the function output true, it’s time to activate thrusters full power, if false, then not yet. So we stay in freefall until the function determines we are bound to crash.
What this function does:
- first, it calculate the lander’s distance_to_ground
- then it runs a loop where it adds the current v_speed (which is negative) to the distance_to_ground, so we are approaching ground.
- then it updates the v_speed adding mars_gravity and thrust_power to it.
- then it bump up the thrust_power if they are not to 4 already.
This loop continue as long as “v_speed < 0” and when it stops (meaning we achieved positive thrust), if the distance_to_ground is negative it means we “penetrated” the ground even attempting a max thrust, so this is the earliest time in which it would be advisable for us to start a max thrust.
this is the code I wanted to share originally (not the wrong one) → #include <iostream>#include <string>#include <vector>#include <algorithm> - Pastebin.com
it’s ok if is a pastebin, right?
Your code works fine on the IDE. Not sure what your problem is? Maybe you mixed up the codes before?
Pastebin is ok, but there are advantages of just describing your algorithm:
-
You may have a re-think about how your code works, and you may accidentally come up with what’s wrong with it while you’re trying to describe it in words.
-
You’re able to compare what you intend your code does (your description) with what your code actually is.
-
Easier for others to understand rather than them having the need to read and try to understand what the code does.
And so the problem is that the landing point is at height “y == 100” but my lander reaches a v_speed of 0/ms 85 meters above it, and stay floating until it runs out of fuel and then fall 85 meters to the groound… I fail to understand why it’s getting at 0/ms v_speed sooner than projected by my function…
It should “penetrate” the ground, meaning when it reach the ground it should have -1m/s v_speed… but that’s not what is happening at all…
Do you mean you’re trying to improve the lander’s performance even though the code works on IDE?
yes ^_^’
I want for this single thrust to be timed such as that it gently touches the ground.
Understood, then it’s a different story. I’ll take another look then.
Thank you
The only explanation I could come up with was that the “mars_gravity” number provided in the problem’s text wasn’t accurate, actually haven’t checked that yet but only because I feel it would be absurd after so many people attempted it, and chances are 99% I’ve messed up the math x_x
No issue with the gravity number in the problem’s text.
While the v_speed given to you is an integer, the actual calculation done by the game engine uses “unrounded” figures. So, there’ll be discrepancies if you rely on the input figures entirely during your simulation.