The Descent - Puzzle discussion


#340

you need to be a bit more explicit, else you probably won’t get much help.

First, you can read a bit of history in this thread, it should answer most of your questions. Then, you can tell us what you tried and what is blocking you.


#341

Hi. Yes, I understand that part now, finally, but that was not clear here:

At the start of each game turn , you are given the height of the 8 mountains from left to right.
By the end of the game turn , you must fire on the highest mountain by outputting its index (from 0 to >7)

The next issue is that it’s unclear to me how they are “given to me” – I can easily modify that for loop that counts from 0 to 7 and put in something silly, like for(int i=-8; i < 0; i++) and the code will still run. Yet clearly that for loop index isn’t what is defining the indices.

Then there’s this:

  • The while loop represents the game.

How? A while(true) loop, in a real coding environment, would crash your system if you aren’t putting a WaitForSeconds call in there or something as part of a coroutine.

  • Each iteration represents a turn of the game
    I don’t know what “turn of the game” means. When the ship flies from left to right? When it flies from left to right and back, making a round trip?

Just giving some ideas as to why this simple puzzle only has a 55% success rate. Maybe it’s a kind of “native English speakers have more trouble with Shakespeare than non-native speakers” situation, but I still think this will confuse a percentage of new coders and/or give them the wrong idea in the long run if they think while loops are this slow.


#342

Try this. Scroll down from the graphics pane where the ship and mountains are. Underneath that is a detailed problem description that answers just about all the questions you’ve asked. On some puzzles it’s not at all obvious that there is more on that pane.

The old hands take it for granted now but I remember having the same complaints in the beginning before I discovered that fact. CG probably ought to look into that on this puzzle in particular since like he said, it probably pushes some beginners to give up too early.


#343

Arrg I will look for that, thanks.

FWIW, myself and the rest of the dev team where I work complain about similar tutorial designs for our own projects all the time, along the veins of “Nobody is going to see/read/get this, boss…”


#344

Hi there!

I’m really new to Codin’ Games and just completed a game but when I went to The Descent I was so puzzled.

This is the code:

    import sys
import 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.


# game loop
while True:
    for i in range(8):
        mountain_h = int(input())  # represents the height of one mountain.

    # Write an action using print
    print("I will destroy you!")
    # To debug: print("Debug messages...", file=sys.stderr)

    # The index of the mountain to fire on.
    print("4")

Could someone help please?

  • Zoe

#345

welcome @TheFirefly, see my answer five posts above.


#346

Hey there,
I am new to this platform and I can’t understand what’s wrong with my code (like a lot of persons here!). I am using PHP, here it is :

while (TRUE)
{
    $mountainsH = [];
    for ($i = 0; $i < 8; $i++)
    {
        fscanf(STDIN, "%d",
            $mountainH // represents the height of one mountain.
        );
        array_push($mountainsH,$mountainH);
    }
    $val = max($mountainsH);
    $highest = array_search($val,$mountainsH);
    echo($highest."\n");
}

I have this infos in the console :

Informations :

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

Sortie standard : 3

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

Height of mountain 0 : 0 Height of mountain 1 : 0 Height of mountain 2 : 0 Height of mountain 3 : 8 Height of mountain 4 : 0 Height of mountain 5 : 0 Height of mountain 6 : 0 Height of mountain 7 : 0

I get that the loop does not carry on. I don’t understand why.
Any help will be appreciated !
Thanks


#347

Hello

It is very strange :neutral_face:
I tried with your code and it works perfectly


#348

Hi there! I just discovered you site through the Game Magazine OyunGezer (OCZ) which is regularly being published monthly. I find CodinGame quite useful and fun. It really helps you to get your foot on the door. For me, the interaction of the program is very successful. So far so good, Until I got stuck on the Decent. I went to school in California United States. Neither I want to go into details in terms of being specific about the name of the College nor I want to complain about anything you guys do out in here. I took some CSCI classes as fallows Introduction to Computer Science prior to Programming classes like C++ (CSCI 14) and Java (CSCI 20) As soon as I completed the first term (it was Spring Term) of the first year of the School, I decided to go on my way with Java between the years 2004 and 2005. However, Years passed, technology has been evolving in a so fast-pace manner that it appears to be not giving you a break. Anyway, what I really want to ask you here _CG_Maxime is that WOULDN’T İT BE NİCE TO GİVE SOME BASİC FLASH BACK İNFORMATİON for Review purposes ON THE LOOP SUBJECT While For/ If Else/ etc. before making us rush or in other words make us jump right into the functionality of the program. Eventhough I try, I’ve never been able to stay on top, especially with developing game programs or anything. As I have just found out and registered for the CodinGame web site and for I gave a long break since College. I found really troublesome to get back on my feet. I definately need some sort of help. Maybe chat rooms or it could be a blog where people actively exchanging their ideas and helping each other. I will definately go around and play with it. I hope I would be able to come up with my own answer to The Decent. ( And also, Could you possibly make a back arrow or some kind of back button to back to the previous While For Loop exercise just before the question of The Decent.) I am extremely sorry for the long message. I think I believe I make myself outrageously clear with these wish lists. :)) Thank You.


#349

Hi!
I’ve used the same code (except print(“4”) line, I’ve print(imax)), and it passed 1st and last challenges. But in 2nd challenge (Scattered mountain), it crashed because of (I think) findin 1st (wich is №3) high mountain, wich is lower that №4. How can I force code to search for highes mountain of ALL, not for the first one?


#350

Hi all! This (below) seems to work for one “turn” of the game but then doesn’t keep the fun going for the second turn (where my dumb code just fires away at the same mountain, no longer the tallest). I’m not sure what I’m doing - am I somehow making a “False” statement ending the loop? It seems like it should just loop right back around?

Help appreciated.

Thanks!

highest_mountain_height = 0
mountain_index = 0

game loop

while True:
for i in range(8):
mountain_h = int(input()) # represents the height of one mountain.
if mountain_h > highest_mountain_height:
highest_mountain_height = mountain_h
mountain_index = i
print(mountain_index)


#351

with the indentations, your code should be more readable …

and if you set/reset highest_mountain_height and mountain_index at the right place, it should work :wink:


#352

Sorry, but I didn’t get it. Why did my ship targeted mountain 7 again, while there is no mountain? Haven’t code changed some key? And, if it haven’t, why?


#353

@_CG_Maxime You have a call to readline() which is not defined in the preset code window. In JavaScript you can’t invoke an unknown function that isn’t defined in the scope of your project. I know what you’re trying to do, applying C# pseudocode to another language but this is a bad example.


#354

Hi! I’m on the second testcase and I keep crashing into the 4th mountain. Why is that? Here’s my code:

print("0")
print("1")
print("2")
print("3")
print("4")
print("5")
print("6")
print("7")

print("land")

#355

Did you check the hints on the left panel?

Each one of your prints corresponds to one turn. By the time you destroy part of the mountain 4 with print(“4”), the spaceship will have done 2 back and forth movements descending (and thus crashing in the 2nd test case).


#356

this follwoing code runs abolutely fine in visul studio ide with the same set of inputs for all types of testcases but when i execute it codinggame ide its failing not sure why.

    using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

class Player
{
    static void Main(string[] args)
    {
     
     int[] arr = new int[8] ;
     int[] arr1 = new int[8];
        // game loop
           while (true)
            {

                for (int i = 0; i < arr.Length; i++)
                 {
                     arr[i] = int.Parse(Console.ReadLine());                   
                 }
                
                Array.Copy(arr,arr1,8);
                arr = arr.OrderByDescending(c => c).ToArray();

                foreach (int value in arr)
                {
                    if (Array.IndexOf(arr1, value) == 0)
                    { continue; }
                    else
                    Console.WriteLine(Array.IndexOf(arr1, value));

                }
                
            }
    }
}

can anyone tell me why the mountains are not sorting and getting fired with this code in coding game ide.?


#357

you can check my comment juste above yours. I hope it helps :slight_smile:


#358

i am sorry but i dont understand… i am sorting the array in reverse order and the output will be as i expected when i run it in visual studio. by any chance, these mountain values are not getting sorted even though i used array sorting?
Could you please let me know


#359

ok, let’s take an example with 3 mountains of height 0,1,4 and your spaceship is at height 5

First turn (first iteration of while loop):
-> you sort correctly and shoot mountain of index 2 (height =4). You also assign a command to shoot mountain of index 1 then of index 0, according to your sorting. But these actions will happen during next turns
your spaceship is now at height 4

Second turn
-> you’re given the new heights of the mountains. Mountain of index 2 is now of height 3 since you shot it the previous turn. It’s still the highest but you already assign to shoot the mountain of index 1. You shoot it this turn and your spaceship descend again (height 3)

Third turn
-> same, the command you assign on first turn is to shoot at the mountain of index 0 whereas the highest is still the one at index 2. You thus crash into it.