The Descent - Puzzle discussion

Small hint…you need to code something that will work with all tests, not hardcoding all solutions and comment innapropriate code for each test…

This game does not have a good explanation. I do not understand how it works this games. They are not a real programming situations. I mean it is not logic what you can do just with a print “index”. if you are a real programmer go to HackerRank. It has much better tests.

i did on the mountain puzzle then i had to click test all something. how are u suppost to make each puzzple peace work? 1-5

You need to read the inputs and process it before doing print.
The inputs in this puzzle are eight integers.
You need to store them and then find the max value from them.

But this puzzle is not asking for the max value. It asks for the index of the max value. How to handle it depends on what data structure you are using.

Ive done a bubble sort on list and reversed the order while printing out, but it didnt work , are sorting algorythms too big of a tool to use on this exercise? i cant find much other choice than doing select sort in naive way on first exercise.
Sure i could use faster algorythm ,but decided to go easy on this one.

You are sorting the height values, and then output the max height?
Of course wrong!

As mention in my previous post, this puzzle asks for NOT the max height, but the index of the max height.

If you choose to use sorting as the solution, you have to sort heights tied with IDs. It can be done by a self defined structure, a class, two arrays, or some other designs your language allows.

At the same time, you can also explore any other algorithms that does not need sorting?

1 Like

Hello I am trying to solve this problem in Java with following commands:
while (true) {

        int imax = 0;
        int max = 0;
        
        for (int i = 0; i < 8; i++) {
            int mountainH = in.nextInt(); // represents the height of one mountain.
            if (mountainH > max) {
                max = mountainH;
                imax = i;
                
        }
    }
 
        System.out.println(imax);
        System.out.println("Debug messages...");  

I pass 1st turn successfully with a mountain height at 9 and then the ship auto destructs without hurting a mountain! It gives me following reason:
“Invalid command sent. It should be an integer from 0 to 7.”

I am quite puzzled as I think the command is ok, anybody can give me a hint or advice please?

Thanks and good day to all!

This line caused error because “Debug mess…” became the second output to puzzle. “D…” is not an integer expected by server.

Besides, you should print output multiple times. Now you are printing once only because you print it after game loop

1 Like

Thx! I confirm it is working now :wink:

I think there is a glitch in this game because a number i did not type kept on repeating and repeating

what should i do?

:confused:

You should review your code before incriminating the game. There is no glitch.

The problem is often between the chair and the keyboard. :wink:

1 Like

yes, I have received the same question, I think is a bug.

as said many times there’s no bugs in this puzzle
393782 players solved it
if there is a bug it is in your code

I have debuged them, it is strange that the real output is different from the result of debug.

while True:
for j in range(9):
s = []
num = 0
for i in range(8):
mountain_h = int(input()) # represents the height of one mountain.

        s.append(mountain_h)  
        
        if mountain_h > num:
            
            num = mountain_h
                              
      
    for k in range(8):
        if s[k] > num:
            print(k)
            
            
            print("%d,%d"%(k,num), file=sys.stderr)

Game information:

Let’s destroy those mountains to secure our landing… Height of mountain 0 : 0 Height of mountain 1 : 6 Height of mountain 2 : 0 Height of mountain 3 : 5 Height of mountain 4 : 0 Height of mountain 5 : 8 Height of mountain 6 : 0 Height of mountain 7 : 6

06

Standard Error Stream:

5,8

Standard Output Stream:

5

Game information:

Your spaceship targeted mountain 5, your altitude is now 9 Height of mountain 0 : 0 Height of mountain 1 : 6 Height of mountain 2 : 0 Height of mountain 3 : 5 Height of mountain 4 : 0 Height of mountain 5 : 5 Height of mountain 6 : 0 Height of mountain 7 : 6

16

Standard Error Stream:

1,6

7,6

Standard Output Stream:

1

Game information:

Your spaceship targeted mountain 1, your altitude is now 8 BOOOOMM!! Nice Shot! Height of mountain 0 : 0 Height of mountain 1 : 4 Height of mountain 2 : 0 Height of mountain 3 : 5 Height of mountain 4 : 0 Height of mountain 5 : 5 Height of mountain 6 : 0 Height of mountain 7 : 6

26

Standard Error Stream:

7,6

Standard Output Stream:

7

Game information:

Your spaceship targeted mountain 7, your altitude is now 7 Height of mountain 0 : 0 Height of mountain 1 : 4 Height of mountain 2 : 0 Height of mountain 3 : 5 Height of mountain 4 : 0 Height of mountain 5 : 5 Height of mountain 6 : 0 Height of mountain 7 : 0

36

Standard Error Stream:

3,5

5,5

Standard Output Stream:

7

Game information:

Your spaceship targeted mountain 7, your altitude is now 6 Height of mountain 0 : 0 Height of mountain 1 : 4 Height of mountain 2 : 0 Height of mountain 3 : 5 Height of mountain 4 : 0 Height of mountain 5 : 5 Height of mountain 6 : 0 Height of mountain 7 : 0

46

Standard Error Stream:

3,5

5,5

Standard Output Stream:

3

Game information:

Your spaceship targeted mountain 3, your altitude is now 5 Height of mountain 0 : 0 Height of mountain 1 : 4 Height of mountain 2 : 0 Height of mountain 3 : 2 Height of mountain 4 : 0 Height of mountain 5 : 5 Height of mountain 6 : 0 Height of mountain 7 : 0

56

Standard Error Stream:

5,5

Standard Output Stream:

5

Game information:

You crashed your spaceship on mountain 5 Height of mountain 0 : 0 Height of mountain 1 : 4 Height of mountain 2 : 0 Height of mountain 3 : 2 Height of mountain 4 : 0 Height of mountain 5 : 5 Height of mountain 6 : 0 Height of mountain 7 : 0

Not strange at all because your code is bugged

Turn 1 : one target , you output one shot
It is right

Turn 2 : two targets , you output two shots
It is wrong because the second shot is applied at turn 3

There’s an issue with javascript:

const mts = mountains;
mountains.sort((a, b) => b - a);

that edits mts, too, although it shouldn’t

Hey Oliver, Indeed I am a beginner, and it is still confusing, I still don’t know how mountains is called, does it loop each time from 0 to 7 or I have make it scan each time.

Still trying to understand the game mechanism.

Hi Metallized,

The 8 mountains have no name. If you want you can call them Mountain0 - Mountain7.

At each turn, aka at the beginning of while(1) loop, the system provides you 8 numbers, representing the heights of 8 mountains. You need to scanf() 8x times to read all values.
Then you use your algorithm to select 1 of them to shoot.
Then we finish this turn, and go back to beginning of while(1) again. The system provides 8 new numbers.

The point in my initial post was, we must do 8x scanf() all the time, even if we don’t need all 8 numbers in the algorithm. Otherwise, the un-read numbers will still be there in the next round.

1 Like

I have a Question, in JS:

const mountainH = parseInt(readline());

I don’t understund this line. Means that readline is equal to the previous for loop? and parseInt is converted it into a Integer?

Did you check the hints on the left of the IDE? The CodinGame system works with Standard Input and Output streams. readline reads the next line in the data sent by CodinGame in the Input stream.