Mars Lander - Puzzle discussion

One possible workaround is to compute your solutions locally. In the code you submit, detect which case are you in, and output the precomputed solution.

As far as I remember, the validators for Mars Lander are not strictly identical to the tests, but very similar (shifted by one unit or something similar), so it should be possible to detect the corresponding case and reuse the solution.

2 Likes

I did this puzzle in each language (except OCaml) and i noticed that the auto-generated code in Scala doesn’t work because of the “X” and “Y” variables name. If you can rename them in Scala i think this puzzle can be perfect. And if you can help me with the OCaml version i will not say no too.

2 Likes

thank you for reporting the issue. It’s an old one that we fixed a few months ago and which is back :thinking:

1 Like

sorry but um… i cant and dont know how to code. what do i do?

it’s really hard to learn to code from scratch on CodinGame. I recommend taking a tutorial online to learn the basics. Then, you’ll be able to tackle the puzzles here.

4 Likes

Episode 1
Input:2500 2500 0 0 500 0 0 (X Y hSpeed vSpeed fuel rotate power)
Output: 0 3 ( rotate power)
Input: 2500 2499 0 -3 499 0 1 (X Y hSpeed vSpeed fuel rotate power)
Output: 0 3 ( rotate power)
I don’t get it. If starting power is 0 how do i get 3 power from the first turn and the second turn the power from the input is 1 and in the output its the same. How does that make any sense

The point is that the power is only ever changed by one in a round. So if you print 3 at the beginning as the target force, it takes several moves for the current force to change.
Example:

Entry: 2500 2500 0 0 500 0 0
Edition: 0 3
Entry: 2500 2499 0 -3 499 0 1
Edition: 0 3
Entry: 2500 2495 0 -4 497 0 2
Issue 0 3
Entry: 2500 2490 0 -5 494 0 3

After these three moves, the speed remains constant at 3.

1 Like

I can’t seem to pass level 1! It confuses me and I don’t understand how to make the straight landing work… I am doing javascript.

The default code outputs “0 3” each turn.
When you test it, you realize that it’s not enough, the ship accelerates too much and crashes.
If you output “0 4” each turn, the landing is way too slow and the test fails too.

So you want to balance your outputs between “0 3” and “0 4”.
Try to find a pattern that works.

1 Like

I have a background in aerospace and love this sets of puzzles

2 Likes

Sir,
You’re 17degrees value helped me solved it. I don’t know why I kept using 15

the Scala stub has been fixed.

Hi,
I tried to do some math to solve this puzzle but it’s looks like that when I printf to check some values it doesn’t do the math. For exemple :
float delta;
delta = (Y * 2);
printf("|%.2f|", delta);
delta = delta / 3,711;
printf("|%.2f|\n", delta);
With Y = 2500 I have : |5000.00||1666.67|
but 5000 / 3,711 = 1347. 34 and not 1666,67
Did I miss something ? :frowning:

Yo !
Everything printed on stdout is considered as an answer. If you want to print some logs, you have to use stderr. For example in C :

fprintf(stderr, "Debug messages...\n");
2 Likes

I just wanted to test the math and didn’t think of stderr… I will try, thank you for reminding me the fprintf function :blush:

1 Like

If it s can help; the math was wrong because I put a coma and not a dot in numbers.

after something similar and a bit of test, I set thrusters to 4 at Y=2187m and I land safe.

I’m working on systematic approach to solve this

Working on simulation (100% correct simulation with collision detection for episode 3) shown me these observations:

  1. x, y, hSpeed and vSpeed have to be internally stored as doubles, because inputs are rounded
  2. rounding = round absolute value and apply +/-sign (not critical knowledge, but -0.5 might be shown as 0.0 vs, -1.0)
  3. x = x + (oldhSpeed + newhSpeed) / 2 not x = x + newhSpeed as you would expect
  4. there are no lines with same x-es (vertical lines) so you can use y = ax + b as a formula for line segment (no need for ax + by + c = 0)

Since point 4 is true, I can use Point In Polygon collision detection against simple vertical line, meaning:

  1. get all lines that has x1 <= x && x2 >= x (where x1 < x2)
  2. compute their a and b
  3. count how many lines are above given point (y <= ax+b)
  4. if there is even count of them collision occurs

Now I’m just thinking about which algorithm to pick for problem solving

2 Likes

Is someone able to help me ? I made my code in c++ but it didn’t work, so I tried in python but it didn’t work too. I went on youtube to understand what was wrong with my code, but it was almost the same. I still copied the code that was on the video I watched, but it didn’t work too. Is there someone who encountered the same problem with a correct code that doesn’t work ?

seems you managed to pass the puzzle. In this case, please think about updating your post to tell you solved your issue and explaining how. I could help others. Thanks!

1 Like