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

# Mars Lander - Puzzle discussion

I tried a physics approach on the mars lander level 1 challenge like this: computing the total energy of the system we get m*g*hf+m*(vf^2)/2=m*g*h1+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: g*hf+(vf^2)/2=g*h1+(v1^2)/2-1*(v1+0.5*g+0.5)-2*(v1+1.5*g+2)-3*(v1+2.5*g+4.5)-4*(h1-3*v1-4.5*g-7); v1 is equal to sqrt(2*g*(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.

**werediver**#6

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

**McKelian**#7

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)

**khatharr**#10

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. : /

**NewboO**#11

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

**jones_gravy**#12

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.

**unrecovered**#13

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

**nickmao**#14

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**

**unrecovered**#15

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 =)

**nickmao**#16

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

**CvxFous**#17

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 ^^

**elemental239**#18

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

**cup_of_tea**#19

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