The Descent - Puzzle discussion


#277

mountainheight = 0
mountainselected = 0
while True:
for i in range (8):
mountain_h = int(input())
if mountain_h > mountainheight:
mountainheight = mountain_h “”“repeats over and over so it doesn’t shoot a lower mountainheight”""
mountainselected = i #command to fire at mountain
#it took me a while to understand it too but clue was mountains always go from 0 to 7 never out of order


#278

remove your “if” statement and make “else” your if


#279

Here’s a hint:
You have to make the mountain with higher height destroy first. Even after a loop it has to skip a lower height mountain “if _____ > input:”
This is my hint to you.


#280

All the playtests work, then I click on submit and the last case doesn’t work. Don’t change a line of code, resubmit and all is fine? What kind of fuckery is this? If its not going to work, why not point out where it failed (which it shouldn’t have)? This is the first “puzzle” I get after some copy and paste test and it doesn’t even work right.


#281

I’m having a lot of trouble understanding this puzzle. What’s making it impossible is that I don’t know where my inputs are coming from. We’re given:
mountain_h = int(input()) # represents the height of one mountain.
And as I understand it, that is going to read down the line 0:9, 1:8 and so on. In a normal situation, I’d parse the code to find the highest number and boom - that’s it.

But since we can’t see where input are coming from, I don’t get how this works. =(


#282

your inputs are read in a loop. that’s why the code stub gives you a while (true) or equivalent in whatever language…

think of it as a turn based game.
each turn (i.e. each iteration of the outer loop) you read 8 integers.
each of those 8 numbers is the height of a mountain.
after that you need to tell (output) which mountain to shoot at.

maybe the stub is confusing? the code given as a default does NOT give you a data structure! it just parses the input… so the default code will read all of those 8 numbers into the same variable… overwriting itself constantly…

it is your task to find a way to store the input and do some magic with them :slight_smile:

my standard first approach to all puzzles is outputting the input
put a print statement (to stderr) after each variable you read… just to see what kind of data you’re dealing with… i ran into the same problem several times: i tried to understand the input without seeing it. always a mistake :wink:


#283

The Java solution code is not working. Please let me know if it works for you.


#284

Just tested it, works 100% in Testcases and Validators.

maybe some cut’n’paste error?
Where does it fail for you?


#286

simply
print(target);
should work. The space and the new-line bother.


#287

I am having the same issue. Any word on whether it will be fixed?


#288

There is nothing wrong with the Java solution code. You actually solved the puzzle with the same code.

What issue did you originally have?


#289

hi so Im very new to this and i dont understand anything please help


#290

In PHP function array_key_last() got
Fatal error: Uncaught Error: Call to undefined function array_key_last() in the answer code


#291

array_key_last is a 7.3.0 PHP feature. The CG current version is 7.2.8; See https://www.codingame.com/faq


#292

Hi. I’m not sure whether it’s allowed to ask or not but I’m new here and I’m on my first problem in the Easy section and I’m still getting to grips with the site. So, I think I solved the first challenge (The Descent) but the console says:

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

This is the algorithm I managed to come up with:

// game loop
while (true) {
    var arr = [];
    for (let i = 0; i < 8; i++) {
        const mountainH = parseInt(readline()); // represents the height of one mountain.
        arr.push(mountainH);
    }

    // Write an action using console.log()
    // To debug: console.error('Debug messages...');
    
    var max = arr[0];
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] > max) {
            max = arr[i];
        }
    }

    console.log(max); // The index of the mountain to fire on.
}

#293

You have to output the index of the max instead of its value.


#294
while 1:
    h = 0
    hmax =0
    
    for i in range (8):
        mountain_h = int (input())
    
        if mountain_h > h :
                h = mountain_h
                hmax = i
                
        print("hmax")

#what’s wrong with my code? HELP PLEASE!!


#295

hmax is the name of your variable. When you add quotes around it, it becomes the string “hmax” that has nothing to do with your variable.

If you want to print your variable, just: print(hmax)


#296

Hi there
I’m having trouble understanding the solution in JS.
The way i read it goes like this(summary):
imax is set to 0. for each iteration of the loop add 1 to i, starting at 0.
mountainH is set to the highest height for each iteration.
then if mountainH is higher than max, imax is made equal to i.

so as i see it imax should only be changed according to the iteration count.
ie. 0 1 2 3 4 ect
I don’t see how the if statement in the loop affects the imax to actually be equal to the highest mountain? what am I missing?


#297

at iteration i of the for loop, mountainH is set to the height of the i-th mountain.