The Descent - Puzzle discussion


#298

thx for the reply :+1:


#299

did you use particles? what package did you use?


#300

As i realized from your code you output is the HEIGHT of the highest mountain instead of outputting the INDEX of of the highest mountain. You should not only save the value of max height but also index of this mountain.


#301

Hello, I need some help understanding why my code which appears to be exactly the same as the provided solution isn’t working.

my solution:

// game loop
      while (true) {
          var imax = 0;
          var max = 0;
           for (let i = 0; i < 8; i++) {
             var mountainH = parseInt(readline()); // represents the height of one mountain.
                 if(mountainH > max){
                    max = mountainH;
                    imax = i;
                }





           }

             // Write an action using console.log()
             // To debug: console.error('Debug messages...');
                print(imax);

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



//hint provided solution
// game loop
        while (true) {
            var max = 0;
            var imax = 0;
              for (var i = 0; i < 8; i++) {
                  var mountainH = parseInt(readline()); 
                   if (mountainH > max) {
                     max = mountainH;
                    imax = i;
               }
          }

                   print(imax);
         }  

I’ve been working on this for hours and then I find out it appears to be something with the challenge itself since I’m not seeing anything different from what I am trying to run and the provided solution

Hi, so I noticed that the provided solution didn’t have this line:

console.log(‘4’); // The index of the mountain to fire on.

I removed it from my code and it passed.
which is extremely frustrating because if you reset your code the console.log(4) is automatically added which means that the module itself isn’t working correctly.


#302

Heya, I’m new here.

After having solved “The Descent” in Python (2) with a plain old for loop and two conditionally updated variables as suggested in the hints, I thought I’d give it another try with functional-style Python 3 and itertools etc.:

:warning: Spoiler warning: I think the code of my attempt should solve the puzzle, even though it fails the tests right now. So if you haven’t solved it yourself yet, you might want to not view the code. :warning:

(code hidden, click to expand)
    import sys
    import itertools
    import operator

    # game loop
    while True:
        # see docs.python.org/library/itertools.html?highlight=take#itertools-recipes
        heights = map(int, itertools.islice(sys.stdin, 8))
        mountain_index, mountain_height = max(enumerate(heights), key=operator.itemgetter(1))
        print(mountain_index)

However, when I start the tests, this just gives me

Timeout: your program did not write to the standard output in due time.

Pasting that code into a local file and running it on my computer, I seem to observe the correct behavior.

I thought maybe the import of the additional standard library modules is taking too long, so I added print("script started", file=sys.stderr) right after the sys import (before the other two imports). Though still that timeout message apparently without any debug output from my program.

What’s going on? Is compiling the script taking too long? Or have I found a bug in the game? Or am I bending the rules too much by changing the template code in places not indicated by the comments?


#303

Hey guys im new to coding and trying to learn python3 anyone got any tips for what phrases to use to find the mountains, i got through test one and it went fine but im having trouble finding a code that will work on all of them.