# Mars Lander - Puzzle discussion

Feel free to send your feedback or ask some help here!

### Level 3

3 Likes

I tried a physics approach on the mars lander level 1 challenge like this: computing the total energy of the system we get mghf+m*(vf^2)/2=mgh1+m*(v1^2)/2-L , where m is the mass, g acceleration, hf final height - 100m, vf - final velocity which iâve set to 40 m/s, h1 height at which thrust starts, v1 - velocity at h1, and L the mechanical work needed to prevent the crash. My goal was to burn the least amount of fuel so i let the object fall freely until height h1 and then i set the thrusters to full (so as to ensure that the time frame in which the module is burning fuel is minimal). Considering the starting point and the landing zone invariant at (2500,2500) and (some_x_interval, 100) i came up with the following equation: ghf+(vf^2)/2=gh1+(v1^2)/2-1*(v1+0.5g+0.5)-2(v1+1.5g+2)-3(v1+2.5g+4.5)-4(h1-3v1-4.5g-7); v1 is equal to sqrt(2g(2500-h1)) - which must be substituted in the top formula, thus obtaining a non-linear equation in h1. First term to the right of the eq sign is potential energy at height h, second is the kinetic energy and the last 4 terms are the total work that the thruster must do in order to keep the vf=40m/s; these come from the fact that the thruster needs 1 second to increase the acceleration by 1m/s^2, so for each acceleration i compute the mechanical work based on the acceleration(1,2,3,4) and their corresponding distance in which that acceleration takes place (i compute the mean velocity for a 1 second interval and multiply it with the time interval - again 1s thus obtaining distance).

TL DR VERSION with my formula iâve obtained a height of 2115.7m at which i must start the thrusters at full which is a wrong answer. If anyone has time please show me where is the mistake in my calculations; if not maybe someone could give an explanation on how to physically compute the height from which the thrusters must go from 0 to 4 so as the landing speed is exactly 40 m/s. While this should be a programming challenge i would want a physical solution, plus it should yield a very efficient program.

5 Likes

Less fuel, better for planet Mars

9 Likes

Seems valid.

click here problem : âUnhandled Error: Undefined variable: displayFullQuestionâ

I configm this problem. Canât get to the full set of instructions by clicking âhereâ link in Chrome 37 on Linux.

Yes, itâs exact, links are broken on level 2 and 3 for mars lander puzzle. You can get information on level 1 (in easy exercices)

Thank you for this hint, @McKelian

You are welcome

Kind of unclear that the first time you play it thereâs only a straight vertical descent, and no further tests. I wasted a lot of time on a more complete solution because I made the mistake of believing what I was told in the description. : /

4 Likes

Thatâs not wasted time, as youâll need your more complete solution for level 2 anyway

2 Likes

I took the shotgun approach. It seems that you need to land with a vertical descent of -20. If you start falling before engaging the thrusters in time then you might have the correct thrust but your descent wonât slow to -20 in time. I came up with the formula to solve it though I am not very happy with the solution for level 1. P = min(abs(VS) / 5,4)
I donât know if my solution will work on levels 2 and 3 but I havenât gotten there yet. I am working through all the âeasyâ games now.

1 Like

WhewâŠ made it at last through the second level. Iâve started and abandoned it several times, but in the end i was victorious! Though there are some codepieces in there that Iâm not proud of. But still, win is a win

About algorythm. Itâs pretty complicated, but rough. First, you need to find angle, that will allow you to accelerate and, at the same time, not to lose altitude, when using throttle 4. Itâs about 17 degrees. Using it, you can relatively comfortably travel across the gamefield. Next, you need couple of ifâs, that can keep shipâs horisontal speed at bay - you donât need to rush too much, especially in some cases, when itâs too high from the start. Donât forget the slowing if - youâll need to nullify your speed once you get close to landing pad. Simply put, you need to alter your angle once youâre near, and, after that, set it to 0 at the moment horisontal speed is nullified. And then, thereâs a landing procedure, which(i hope) youâve already mastered on level 1

11 Likes

Itâs actually (+ / -) 21.9 deg:) but hSpeed will be quite bigger, so you need to brake after strafing.

If you donât want to hardcode that:
We have G (3.711) and we have Pmax = 4 (max throttle).

To strafe freely we need to find an angle (either positive or negative), which will split Pmax vector to two components: horizontal one (no matter what it will be) and vertical one, should be equal to or approximate to our G (3.711) to strafe.

Itâs simple:
cos Î» = G / Pmax (to get vertical part of split vector)
Î» = acos (G / Pmax)

So, basically, whatever you update G or Pmax, you can always calculate strafe angle.
In our case:
Î» = acos(3.711 / 4) = acos(0.9275) = 21.9

12 Likes

Yeah, youâre right, it looks more optimal that way =) Thought lander still loses altitude and i have no idea why =\ I couldnât finish fourth test because of it, and taking in account heights on the way to the landing pad looks like a pain

I donât know if itâs a bug in game engine or my miscalculations, but there are some strange bugs like this. For example, when i try accelerate till the halfway, and then decelerate on the other half(starting speed 0, same throttle and angle), lander doesnât end up in a position it should be.

So in the end Iâve just set the speedlimit and angle i found during several tests. It works, for the better or worse =)

You can start strafing with t (time) equal to 4 (1, 2 and 3 throttle, then 4 as a max).
During that time, you earn some vertical speed.
Itâs because you output 1, 2 and 3 m / s ^ 2, and with angle (15, 22). You donât extinguish G which is equal to 3.711.

Because G > your throttles for these 3 turns, you gain vertical speed of 6m/s ^2 (approximately), and YOU KEEP IT BY KEEPING ANGLE AT 22. So basically you need to include extra logic into your code That when you are 22 deg and 4 throttle, your VSpeed should be 0

Iâm so jealous for you, because i only do math now. Canât code second level

1 Like

In a way, thatâs what bother me with this puzzle. In the end, itâs more about âHave you listened in high school?â than about Code ^^

4 Likes

There is an additional achievement at level 1. My code provide needed solution (I tested), but I didnât get it.

You tested on ide. You canât know if it pass on submission (input is different). I have this success, so it should work.

1 Like

omg more achivement i see one more in skynet finale 1 too, cool stuff