The Descent - Puzzle discussion

worst first game ever :smiley: totally unintuitive. hackerrank is better :slight_smile:

Yeah ! Totally agree with you ! You’ll be happy on hackerrank ! Farewell !

yeah, good idea, best regards for all!

It’s not the first one. :expressionless:

My code passes the first two tests, but not the third and I’m not sure why?

// game loop

let map = new Map();

while (true) {

    for (let i = 0; i < 8; i++) {

        const mountainH = parseInt(readline()); // represents the height of one mountain.

        map.set(i, mountainH);

    }

    const mapSort1 = new Map([...map.entries()].sort((a, b) => b[1] - a[1]));

    for (let index of mapSort1.keys()) {

        console.log(index); 
    }
}

You are not outputting the answer correctly

By the end of the game turn, you must fire on the highest mountain by outputting its index (from 0 to 7).

Your code is outputting several values for a single turn (conole.log() in a loop)

1 Like

Absolutely.
What is this?

Simplicity and clear logic. Starting from requirement(s).
Is this showing off everything than real coding and logic?!

i dont understand coding i am new and i want to learn but i dont understand so i am not getting any progresjon i have tryed this for a week but i cant understand

https://www.codingame.com/forum/t/beginner-coding/1926

You don’t have to be a good programmer, but you do need to know some basic stuff before this site makes sense.

To do the Easy section of the Training area, you need to know comparisons, arrays, and loops. IIRC one of them almost forces you to use a Dictionary/Hashmap (which is trivial in C# or JS). Knowing a bit about working with strings is helpful. If you don’t know that stuff yet, I’d recommend spending some time on Codecademy or any of the multitude of tutorial websites out there before you tried the puzzles here.

I was confused because i thought i need to write the code to destroy the mountains too (reduce the highest mountain to 0). Did I miss the question in some way?

Welcome to Codingame!

It would help if you described the exact problem you are having. Without that I can only guess at what the issue might be. However, I will say that outside of basic syntax and logic errors, the most common mistake people make is outputting the height of the mountain they’re firing at rather than its index.

One thing that is not obvious at the beginning is that there is a very detailed problem statement available. This includes the format of the inputs you’ll be given, what they all mean, and what your outputs are supposed to look like. Just scroll down inside the panel with the graphics and it’ll tell you what you’re supposed to do.

1 Like

I’m not a smart person, but can anyone explain to me in simple way what’s stdin and how it relates to the game?
And also…
for i in range(8):
mountain_h = int(input())

what is the value in ‘i’? (is ‘i’ our plane?)
i might be wrong but doesn’t input() , means for the user to input the variable?

Please advice. I’m confused how to even start playing these game

Hello, I think can help:
https://www.codingame.com/playgrounds/55547/how-to-get-started-on-codingame

also you can check the hints of this puzzle (in the left menu)

what is the meaning of imax?

why cant it be :
while True:
hmax = 0 # the highest mountain
for i in range(8):
mountain_h = int(input()) # represents the height of one mountain.
if mountain_h > hmax:
hmax = mountain_h
hmax = i
print(hmax)

thank you

You have assigned hmax to firstly mountain_h and secondly i. In the next round of the for loop, can you see what you are actually comparing mountain_h with?

i didn’t understand what you mean

You have these two lines in your code. Without proper indentation I am assuming they are all inside the “for i in range(8)” loop. In that case,

  1. Will the value of hmax change if firstly “hmax = mountain_h” and secondly “hmax = i”?
  2. In your “if mountain_h > hmax:” statement, you are comparing mountain_h and hmax. But think hard about what hmax actually is, in light of question 1 above.
  1. ok i understant what you wrote.
  2. hmax is ths highest mountain, acoording to what i wrote
    *and can you tell me pls what is the (imax) ? acoording to the solution?

The puzzle asks for the index of the highest mountain, not the height of the highest mountain. So there are separate variables to store the values.

thank you very much