The Descent - Puzzle discussion

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

WARNING: The rules of this game have been changed on March 3, 2016.


So The descent became what the previous onboarding was? Why this one specifically?

1 Like

The reason why we have simplified this puzzle is the following:

Once the on boarding completed, new codingamers start Power of Thor and then The Descent. However, for new comers on CodinGame, these puzzles are a bit hard to solve: the statement is too long and they have to deal with details that are not really interesting.

For instance, regarding Power of Thor: you need to understand the while loop, you need to update your variables, you need to do multiple prints or concatenate variables, etc. And for The Descent, the statement stated that you could fire only once but it was fine to try to fire multiple times…

But you are right that, a long time ago, our on boarding was similar to the new The Descent, but we didn’t want to keep the same game for both the current on boarding and the first puzzle. We decided instead to take The Descent, simplify its statement and move it as the first puzzle instead. We will also simplify Thor at some point.

Basically, the new The Descent requires to implement the same algorithm but it is just easier to understand what must be done.


Makes sense. I have a very minor wording correction:

“you must fire the highest mountain”

should be

“you must fire on the highest mountain”

  • danBhentschel

Will the code golf challenge be impacted by that?

Hi, just a warning that the solution for this puzzle in python3 given in the hints assigns to the max built-in (which now is a variable).
That’s a very dangerous habit! Say someone imports your file and then tries to do max([1,2,3]), they’ll get an error!


Where is the input? I can never see the list of mountains…


I think I found a bug of the game simulator for C language. How should I report it?

1 Like

Just tell us how to reproduce here, but you can also do it in private or by sending an email to coders at

1 Like

I found out why.
The game requires scanf() 8 times each turn to get all mountain heights. But I used “break” as soon as a height == 9 is found, because this is the max possible.

E.g. If mountain0 is 9, I’d break and do printf(“9”) directly, without scanf() other mountain1-7.
But at next turn when scanf(), the value is still mountain1 from last turn, not the new value mountain0.
Hope I explained myself clearly.

The game mission says:
“Input for one game turn
8 lines: one integer mountainH per line. Each represents the height of one mountain given in the order of their index (from 0 to 7).”
But it doesn’t say you need to read them all. So I kinda assumed the lines are refreshed at the next turn, i.e. next loop of the while(1).

For codingame beginners it takes a while to understand how inputs are given exactly …


I’ve a question… (Yeah, I do realize there is a simpler way without using arrays at all, I just wanna know why my code isnt working).

In my code I saved all the mountain heights in an array, then used another for loop to compare each array entry with the max variable (target_h):

        target_h = mountain_h[i];
        target = i;
printf("%d \n", target);

For all the cases it prints the correct number, and since I used %d, it obviously is an integer, but I always get error:

Invalid command sent. It should be an integer from 0 to 7.


Superlfuous space between number and newline?

1 Like

Yep, that was it, thank you.

I just did this thing in C++. The game tells me my output is ‘0’, however all real compilers I tried output the correct answer ‘1’. I wonder why is that?

Here’s the essence of my solution:

int main()
    std::vector< int > heights;
    // game loop
    while (1) {
        for (int i = 0; i < 8; i++) {
            int mountainH; // represents the height of one mountain, from 9 to 0.
            cin >> mountainH; cin.ignore();
            heights.push_back( mountainH );

        size_t index = std::distance( heights.begin(), std::max_element( heights.begin(), heights.end() ) );
        cout << index << endl; // The number of the mountain to fire on.


1 Like

A question , there is a while true and a for inside, for the basic logic the for need run each time and after move out for to do next instruction. Why in this code each System.ou.println is execute out the for? If the for not end how it moves out the for loop? (Got what I mean?)

Use Linq.
it will make great and simple code.

Hey guys I’m new to this site and have a question. When taking in the mountain Heights in this loop why is cin.ignore() called?

for (int i = 0; i < 8; i++) {
int mountainH; // represents the height of one mountain, from 9 to 0.
cin >> mountainH; cin.ignore();

wouldn’t this function exactly the same without that line? Thanks!

1 Like

Hello. I think the pseudocode for this problem is wrong. It has the print statement inside the for loop, but the solution has it outside of the for loop.

1 Like

@analyst153 You are right, if you compare the pseudo code to the solution the print(imax) is inside the for loop. This doesn’t work and needs to be outside of the loop.

i have following code which should work perfectly

var heights=[]
   for (var i = 0; i < 8; i++) {
        heights.push(parseInt(readline())); // represents the height of one mountain, from 9 to 0.
while (true) {
    // Write an action using print()
    // To debug: printErr('Debug messages...');
    var index=heights.indexOf(Math.max.apply(null,heights));
    print(index); // The number of the mountain to fire on.

but it is not working . i also tried with c equivalent code for c it does not work either so i assume theres a bug in the game . I had this issue with some other games as well either i misunderstand something or this for months theres are similar bugs in most games and nobody tries to fix them