well i tried a different way but doesn’t seems to be working, i write that if (v_speed <= -40) then v_speed = 4 but the thruster always seems to be on which confuse me
Would you please:
(a) specify which episode of Mars Lander you are working on?
(b) specify which test / validator you are working on?
(c) share a replay link? (Use the button called REPLAY AND SHARE at the bottom-right corner of the viewer.)
Bonjour, le lien vers le “calcul de vitesse” dans l’énoncé est mort.
can anyone better at programming(literally anyone reading this) give me an example of how i can program a solution for this challenge and it NOT be hard coded. (i’m passing the test challenge but not the final solution for challenge 1)
i just did ( in cpp)
if(y>2300) do this much power
else if (y>1960) to full power
and that was that. but when i try to submit the code it says the final tests are different to disuade HARD coded solutions… HOW the heck else are you suppose to do it?
these games are frustrating because this site doesnt exactly tell you how to do anything with the game or any game.
If you’re talking about Episode 1, the site does tell you what to do: there’s a HINTS button to the left of the puzzle statement.
And when there isn’t such a button for a certain puzzle, you can always find the relevant discussion topic in this forum, state what you’ve tried to solve the puzzle, and ask about the problem you’re facing.
I tried using while loop for this. But it doesn’t seem to work
The code in kapsh’s message is just an example. You have to do more than that.
while (true) {
var inputs = readline().split(' ');
const X = parseInt(inputs[0]);
const Y = parseInt(inputs[1]);
const hSpeed = parseInt(inputs[2]); // the horizontal speed (in m/s), can be negative.
const vSpeed = parseInt(inputs[3]); // the vertical speed (in m/s), can be negative.
const fuel = parseInt(inputs[4]); // the quantity of remaining fuel in liters.
const rotate = parseInt(inputs[5]); // the rotation angle in degrees (-90 to 90).
var power = parseInt(inputs[6]); // the thrust power (0 to 4).
function reverseTrust(Y, vSpeed) {
if (Y = 1000) {
for (power = 4; vSpeed > 40; power--) {
return power;
}
}
}
console.log(0, reverseTrust(vSpeed));
// Write an action using console.log()
// To debug: console.error('Debug messages...');
// 2 integers: rotate power. rotate is the desired rotation angle (should be 0 for level 1), power is the desired thrust power (0 to 4).
}
Can anyone tell me what I’m doing wrong? I’m having a hard time understanding STDIN and STDOUT.
In the case of a function, the input to a function is the parameters, and the function may output the results with return
.
In the case of CodinGame puzzles, you read inputs with STDIN (readline() in your case), and you output results to STOUT (console.log in your case). You don’t use return
. Of course, you can still use functions within your code, but to communicate with the CodinGame website, you ultimately still need console.log.
And in your code, your reverseTrust
function won’t return anything when Y ≠ 1000.
Did anyone solve for the flat surface using landX and landY? I’m thinking like this:
let points = [];
const surfaceN = parseInt(readline()); // the number of points used to draw the surface of Mars.
for (let i = 0; i < surfaceN; i++) {
var inputs = readline().split(' ');
const landX = parseInt(inputs[0]); // X coordinate of a surface point. (0 to 6999)
const landY = parseInt(inputs[1]); // Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars.
points.push({ x: landX, y: landY });
}
let flatLines = [];
let start = 0;
while (start < points.length) {
let end = start;
while (end + 1 < points.length && points[end].y === points[end + 1].y) {
end++;
}
if (end > start) {
flatLines.push([points[start], points[end]]);
}
start = end + 1;
}
Your code looks correct to me.
With a few exceptions (Level 1 of Mars Lander and several official Easy puzzles), please refrain from posting working code on the forum. If you have any questions, it’s generally better to describe your issue and explain the approach you’ve tried rather than sharing a code directly.
Hello, can i have some indication plz with my code ?
while true do
next_token = string.gmatch(io.read(), "[^%s]+")
X = tonumber(next_token())
ect ..
power = tonumber(next_token())
if (vSpeed <= -40) then
power = power + 1
rotate = 0
elseif (vSpeed >= -40) then
power = power - 1
rotate = 0
end
print(rotate..power)
end
It looks like you’re trying to solve Episode 1 using Lua. I can see 3 issues:
- power is 4 at maximum. If you output a power greater than that, you will automatically fail.
- power is 0 at minimum. If you output a power less than that, you will automatically fail.
- rotate and power should be separated by a space when you print them.