The Descent - Puzzle discussion


Hi, can you tell me, what is wrong?

int hight = 0;
	int highest = 0;
	int highestindex = 0;

int main()

    // game loop
    while (1) {
        for (int i = 0; i < 8; i++) {
        if (hight > highest){
				   highestindex = i;
				   highest = hight;}
            cin >> hight; cin.ignore();

        // Write an action using cout. DON'T FORGET THE "<< endl"
        // To debug: cerr << "Debug messages..." << endl;

        cout << highest << endl; // The index of the mountain to fire on.


i won’t spoil giving you the answer but only clues.

2 huge errors in your solution :

  • you are supposed to get mountain’s height before comparison.
  • you should take care that your variables have good values at each loop


Hey guys,

I’m new to this site.

I read a few tutorials online for javascript beginners (functions, loops, arrays… basic stuff), wanted to try some exercices to train before I go any further. So here I am and… I’m getting so frustrated because we can’t see the solutions.

I read the exercice and I’m lost… I have no idea what to do.

After spending 20 minutes on scratching my head I finaly saw the “hints” on the left… they talk about stdin stdout stderr… Are we suppose to use these words in our solution ? (How I’m I suppose to know these? I’ve never heard of them before :frowning: )

I read the algorithm & pseudo-code which I believe is the “solution” but I have to write it down with proper code and I don’t even know where I have to write it… Is it inside the for that is already there ? or make a new one underneath ?

I tried doing things with typeof, tostring… When I write these down outside the for it says undefined (I guess it’s because of the “scope” ?) when I write it down inside the for it’s fine.

I am a complete begginer, even with the last hint I can’t understand what to do. If you guys got any hint for me… <3

(trying to do it in javascript)

Edit : Ok so I checked the answers above to get some answers, saw that I had to write the code around what’s already written… managed to complete the exercice but with no joy because I didn’t understand it on my own… feels Weird :confused: will try other exercises. <3


Hi! And welcome to CodinGame :slight_smile:
Sorry that you’ve had a hard time. The first learning step here is the harder.

Maybe you can point me at what isn’t clear in the hints? I have modified them recently and I’m looking for feedback.



Why doesn’t this work?

class Player
static void Main(string[] args)

    // game loop
    while (true)
        int max = 1000;
        int number = 0;
        for (int i = 0; i < 8; i++)
            int mountainH = int.Parse(Console.ReadLine()); // represents the height of one mountain.
            if (max > mountainH) {
                max = mountainH;
                number = i;



if max is greater that mountain’s height … so you choosed to destroy the lowest mountain …?


TRY THIS :wink:

[no full solution please]


Hello, my Code does not work and I dont know why.:

import sys
import math

while True:
    moutain_h = 0
    highest_mountain_h = 0
    highest_mountain_index = 0
    for i in range(8):
        mountain_h = int(input())  # represents the height of one mountain.
        if mountain_h > highest_mountain_h :
            highest_mountain_index = i
            Highest_mountain_h = mountain_h


Maybe if you print the right variable it will work


Is it me or is this game “API” is nonsensical ?


Why doesn’t this work?

int main()
int max;
// game loop
while (1) {
    max = 0;
    for(int i = 0; i < 8; i++){
        int mountainH;
        count >> mountainH; cin.ignore();
        if(mountainH > max){
            max = i;
    // Write an action using cout. DON'T FORGET THE "<< endl"
    // To debug: cerr << "Debug messages..." << endl;
    cout <<  to_string(max)  << endl; // The index of the mountain to fire on.



Because in your code, max is an index AND a height.


Why this doesn’t work? i think there’s a bug

 import java.util.*;
import java.math.*;

 * The while loop represents the game.
 * Each iteration represents a turn of the game
 * where you are given inputs (the heights of the mountains)
 * and where you have to print an output (the index of the mountain to fire on)
 * The inputs you are given are automatically updated according to your last actions.
class Player {

    public static void main(String args[]) {
        Scanner in = new Scanner(;

        // game loop
        while (true) {
            int max=0;
            int index=0;
            for (int i = 0; i < 8; i++) {
              int mountainH = in.nextInt();
                System.err.println("mountainH est"+ mountainH);
                if (mountainH==9)
               // removing this if block makes it work     
                if (mountainH>max) {
                max= mountainH;
            System.err.println("broke out");

            // Write an action using System.out.println()
            // To debug: System.err.println("Debug messages...");

            System.out.println(index); // The index of the mountain to fire on.

i remove the part of comparing the mountainH to 9 it works


I find this extremely confusing. It took me long enough to figure out why the game loop wasn’t happening at a standard framerate of between 30, 60 or 100 times per second. When I finally figured out – or did I? – what a “turn” is supposed to mean, I wrote this code:

while (true)
         List<int> mountains = new List<int>();
         for (int i = 0; i < 8; i++)
             int mountainH = int.Parse(Console.ReadLine()); // represents the height of one mountain.
       Console.Error.Write("sorted" + mountains.Count + "," + mountains[mountains.Count-1]);

        Console.WriteLine(mountains.Count-1); // The index of the mountain to fire on.


It does not work. It never shoots down mountain of height 9, despite the fact that said mountain is lying right at mountains[mountains.Count-1] after I sort it. I think there’s a bug somewhere in your engine code that’s ignoring the new, sorted indices and using some fictional indices that we can’t see under the hood.
(as a side note, I did clear the mountains list between “turns” initially as well, but with the sort and the weirdly infrequent iteration of the while loop, it’s pointless)


Of course it does not work…

Your code will always print the number of moutains-1 … it is not the position of highest mountain !!!

List in not a good datatype for your algorithm.
Moreover you don’t really need to do like this (there is a more simple solution)


Did you not see my sort command? By the unusual logic of writing the indices to destroy mountains, the last index of that list should and does always have the highest mountain. Also, with the loop being called once per “turn”, it doesn’t matter. I was trying all options to see how malleable the interface was.


Yes i have seen your “sort” … but have you read your code ?

You are just printing “mountain.Count-1” … which wil always return 7 …


Have you? Writing the index of the highest mountain is what you’re supposed to do. When I sort them, the index of the highest mountain is always 7. I even checked that with the debugger.

Look, I’m sorry to be blunt to the point of being typical ornery software engineer-ish, but at the very least, there is a fundamental communication problem with the way these puzzles are described to the end user. There is zero explanation of where these magic indices come from, where they are stored, why the indices I use in my list don’t map to them properly, or what data connects Console.Writeline(index) to the actual mountain.

This would be an absurdly simple problem to solve in real C#, in a real Unity environment, yet in this venue it’s giving me, an admittedly dense in certain ways, but still experienced programmer, a lot of trouble. It’s making up weird rules and hiding code, and IMO, nothing good can come from that in the long game. In a framerate loop, I would not use a sort for each frame (although the default comparer is Quicksort, which is good), but a test environment like this should be able to understand what I’m trying to do.


hello and welcome to CodinGame @MichaelGreenhut

I totally understand you get confused on your first steps on the platform while being an experienced programmer.

Have you, by any chance, seen the hints on the top left menu?

Now, about your code:

  • if you sort a list of integers, the index of the highest integer will always be the last one (size - 1). However, the puzzle asks you the index of the highest mountain as they are given to you, not after you sort them.

Does it help? I’ll be happy to answer any question you might have.


i need help