The Descent - Puzzle discussion

Now it works perfectly fine for all testcases. The mistake was that I had to remove the quotes in Syso, so that JAVA was able to access the variable. Wow, such an easy fault and I didn’t see it the whole time. But thanks for your help and your patience. :slight_smile:

I don’t know why it isn’t working, I thought it would have.

import sys
import math

# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.


# game loop
while 1:
    max = 0
    imax = 0
    for i in range(8):
        mountain_h = int(input()) # represents the height of one mountain, from 9 to 0. Mountain heights are provided from left to right.
        if mountain_h > max:
            max = mountain_h
            imax = i

    print(imax)

EDIT : I understood, I didn’t deleted the “print(“4”)”.

2 Likes

Great site and great pazzle. Thanks Guys!

Aside from looking at the solution are there any other resources I can pull from online? Once I read the solution it all makes sense, but just looking at it with no exp. I was like wtf lol.

If you’re looking for a thorough explanation, I advise you to check the video of Master Hellish: https://www.youtube.com/watch?v=t-tPMY9wdE8

(it’s part of the given resources, on the details page of the puzzle (before entering the IDE))

Some people are confused about differences between imax and max.

imax = mountain position
max = mountain height

I have a question.
I’m doing this in C#, I learned code using Unity. I’m trying this for the first time and I don’t really know how to do much outside of Unity. How do I specify one mountain in mountainH?

Each time you read mountainH, you’re getting the height of one of the mountains. Each one can only be read once (per turn) because that’s how console inputs work. So you’ll need to write the code to either examine the heights as they come in and print the answer after you read them all, or store them and examine them after they are all read.

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:
    max = 0
    imax = 0
    for i in range(8):
        mountain_h = int(input()) # represents the height of one mountain.
        if mountain_h > max:
            max = mountain_h
            imax = 8
        end if mountain_h < max
    
        

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

    # The index of the mountain to fire on.
        print("0")
    end for 

I have this code. Before all this i just had the print (“0”) through print (“7”) and that way i just cleared the first test case. But for the second test case i couldn’t start on it, so tried end statements. It only got more complicated from there. I don’t know if i should just keep the print 0 - 7 to clear the objects. My only problem is looping in general.

For some reason my c++ solution looks good using a cerr, but when I use a cout, it gives me the error “Invalid command sent. It should be an integer from 0 to 7.” I used a value returning function in there of type int. How can it be that I’m not sending an interger when I send the direct output of the function to the cout like cout << theTarget(heights) << endl;

here is my function:

int theTarget(vector &v){

int tallest = v.at(0), target = 0, index = 0;
for(int i = 0; i < v.size(); i++) {
     if (v.at(i) >= tallest) {
        target = v.at(i);
        tallest = v.at(i);
        index = i;
     }
}
v.at(index) = 0;

return (int)target; // I even type casted 

}

Any help would be appreciated.

Be sure to return the index of the mountain, not its height.

Can anybody help me. I can’t figure it out. It gives me this error “Parse error: syntax error, unexpected ‘=’ in the answer code
at line 25”

MY CODE:
<?php

while (TRUE)
{
     $mountainH = 0;
    $highestMountain = 0;
    $highestIndex = 0;
    
    for ($i = 0; $i < 8; $i++)
    {
        fscanf(STDIN, "%d",
            $mountainH
        );
  
  if(mountainH > highestMountain){
        highestIndex = i;
        highestMountain = mountainH;
      }
    }

    echo(highestIndex\n); 
}
?>

What happened to the $s in front of your variables?

  • danBhentschel

When coding this in C,

int hmax, imax =0;

does not work (output is always 0 instead of the index of the highest), but

int hmax = 0;
int imax =0;

as in your suggested solution does work. ==> Bug?!

Hi,
I might have found a bug while trying this game in c# platform.
This is how I did it:
I declared my local variables(max,imax) after main() instead of under the while loop as the solution suggests.
all my test cases kept failing. It shouldnt matter where my variables are declared in this program. It should always yield the same result.
Thanks.

It doesnt matter if the declarations are in same line or different line.
What matters is where those declarations are.
Try placing your declarations under while loop. It will work in both cases. Just found it.

This is my first code here…

Can anyone tell me why my code didnt get acceoted

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

/**
 * 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 int findTheHighestMountain(List<int>list)
    {
      return  list.Max();
    }
    //public static void fixTheList(List<int> list)
    //{
    //    while(true)
    //    {
    //        int max = findTheHighestMountain(list);
    //        return max;
    //    }
       

    
    static void Main(string[] args)
    {

        // game loop
        List <int> heights = new List<int>();
        while (true)
        {
            for (int i = 0; i < 8; i++)
            {
                int mountainH = int.Parse(Console.ReadLine()); // represents the height of one mountain.
                heights.Add(mountainH);
            }

          
            
                while(heights.Any())
                {
                 int max=findTheHighestMountain(heights);
                 Console.WriteLine(max);
                    heights.Remove(max);
                }

                
            
      

            // Write an action using Console.WriteLine()
            // To debug: Console.Error.WriteLine("Debug messages...");



            Console.WriteLine("4"); // The index of the mountain to fire on.
        }
        
    }
}
Game information:
Invalid command sent. It should be an integer from 0 to 7.

Check out what the console logs! :wink:

I’m currently using java what happend to x++; and x = x +1; ?

Hi guys, i guess i am a worse case scenario couse am clueless jst started learning C which i havent yet came to fully understand it, i need help please
:sweat: