Kirk's Quest - The Descent - puzzle discussion (old)

       int imax = 0;
        int max = 0;
        for(int j=0;j<8;j++){
            if(max<mountainH){
                max = mountainH;
                imax = j;
                
                }
            }

But I always get:

Standard Error Stream:
error: cannot find symbol

            if(max<mountainH){
                   ^

Edit: if I restart puzzle and only use System.out.println(mountainH); I get the same error.

I am using Java if that was unclear.
Tried the same with JavaScript and it worked.

for hint have wrong pseudo code:

read space_x and space_y
max ← 0
imax ← 0
for i starting from 0 to 7 do
read mountain_h
if mountain_h is greater than max then
max ← mountain_h
imax ← i
end if

if space_x = imax then
	print FIRE
else
	print HOLD
end if

end for

right:

read space_x and space_y
max ← 0
imax ← 0
for i starting from 0 to 7 do
read mountain_h
if mountain_h is greater than max then
max ← mountain_h
imax ← i
end if
end for
if space_x = imax then
print FIRE
else
print HOLD
end if

Hi!
I am struggling with Mission 2.
I am doing it in C++, I 'll paste my code and explain what I do and why I don’t understand it doesn’t work.
So here’s the code:
[EDIT: NO FULL CODE]

So basically, every time I am over a mountain I check if I am going to crash into it next turn, and if so I shoot, calculating the difference between the mountain’s high and my high.
However on mission two, when I am on top of the 7th mountain, my ship doesn’t fire, even though my ship is higher than the mountain by one point.
Any help would be greatly appreciated.

Don’t check

You need MAX mountainH.

I am trying to finish the mountain puzzle in python and the test cases all run successfully. However after submitting it claims “Multiple Mountains 1” to have an error. when I try to replay from the results I get an error:
An internal error occurred (#545): “Referee error”.

You mean the error is not in the console, but in the IDE right After submitting or compiling?

I believe there is an email adress to report this error to the dev team in the error message. If so that might be a place to start.

I had this behavior a few time this weekend. It is not related to this specific puzzle so far I knoe :wink:

Heading Complete Newb

I have hardly done any coding (i.e Twitch, Prompt) but I thought this sounds like a really awesome way to learn a new language. The tuto suggested Go so that’s where I am right now. It seems simple enough to translate so far. So I would like to know if there are ant Go fans that would like to help a curious gamer? Please let me know.

E-mail: chswllms@gmail.com

It’s been really annoying me that I couldn’t get it to work. I was thinking that there is something wrong with the environment because I couldn’t implement things the way I thought I should be able to. Then I found that the language had been set to C++ and not Java. Finished in 5mins after that :\

I can’t figure this out. I wish I had better debugging tools, but in the meanwhile, the program will not register the highest mountain value. See the code below. The entries in bold are what I added.

This works until the last and second-to-last test run where the ship skips over the highest mountain ranges and crashes on the return.

Even on earlier test runs, it will still fire at mountains that have lower altitudes over high altitudes.

Can you see what’s wrong?

Thanks!


int main()
{
** int mountainHeight[8];** //Declare an array for the program to evaluate all mountain heights.
** int highestMountain = 0;** //Initialize the variable we’ll use later.
// game loop
while (1) {
int spaceX;
int spaceY;
cin >> spaceX >> spaceY; cin.ignore();
for (int i = 0; i < 8; i++) {
int mountainH; // represents the height of one mountain, from 9 to 0. Mountain heights are provided from left to right.
cin >> mountainH; cin.ignore();
mountainHeight[i] = mountainH; //Initialize the array with mountain height values.
}

   ** //Find the largest index.**

** for (int i = 0; i < 8; i++)**
** {**
** if (mountainHeight[i] > highestMountain)**
** {**
** highestMountain = i; ** //Supposed to store the largest mountain value, however, stores other values instead.
** } **
** }**

    **if (spaceX == highestMountain)**

** {**
** //cout << spaceX << endl;**
** cout << “FIRE” << endl;**
** highestMountain = 0; ** //Reset mountainHeight to zero and re-evaluate the heights.
** }**
** else**
** cout << “HOLD” << end**
}
}

Seems to me like the test cases do not agree with the rules. The rules say

At the start of each game turn, you are given:

  • the variable spaceX: the horizontal coordinate of your ship (0 to 7)
  • the variable spaceY: the altitude at which your ship is advancing in kilometers (10 to 1)
  • the height of each mountain from left to right (8 values mountainH)

in total 10 values. Tests 1 and 2 have 9 values each. Some tests have even 12 values. Please take a look.

1 Like

I#m really fresh, but this seems hard.
I program in Python and I try to treat mountain_h as a list, but I cant’ get any results.
So this is the important line I came up with:

 bigM = max(mountain_h)
 if bigM == mountain_h[0] and space_x==0:

But I get a message:TypeError: 'int' object is not iterable

I hope someone can help me, to find the mistake.

This problem was just removed ? I just solved it with a second language, and now it is not in the list of problems. Is it a bug ? Temporary problem ?

Hello, we’ve been performing maintenance on that puzzle. The rules have changed and we have reset everybody’s codes. It is back now. I apologize for the inconvenience.

Hi, I’m solving this in Scala with a functional style, my solution work in finding the highest mountain, at least on my IDE, but here the console prompt me: “Timeout: your program did not write to the standard output in due time.”
This is my code:

object Player extends App {
  // game loop
  while(true) {
    def loop(idxs:List[Int], mh: Int, tmpTop:Int, idx:Int):Int = idxs match{
      case _ if idxs.isEmpty  => idx
      case _ if mh > tmpTop   => loop( idxs.tail, readInt, mh, idxs.head )
      case _ if mh <= tmpTop  => loop( idxs.tail, readInt, tmpTop, idx )
    }
    println(loop((0 until 8).toList,readInt,0,0)) // The index of the mountain to fire on.
  }
}

Any idea what is wrong here?

ok, I got it.
the problem was that my code called readInt one time too much just before exiting the recursion (in order tho get to the isEmpty case).
This new code is working but it is not very elegant in my opinion.

object Player extends App {

    def loop(idxs:List[Int], mh: Int, tmpTop:Int, idx:Int):Int = idxs match{
      case _ if idxs.isEmpty => idx
      case h :: Nil if mh > tmpTop => loop(idxs.tail, mh, mh, h)
      case h :: Nil if mh <= tmpTop => loop(idxs.tail, mh, tmpTop, idx)
      case h :: tail if mh > tmpTop => loop(tail, readInt, mh, h)
      case h :: tail if mh <= tmpTop => loop(tail, readInt, tmpTop, idx)
    }
  
  while(true) {
    println(loop((0 until 8).toList, readInt, 0, 0))
  }
}
1 Like

can anyone help me to explain javascript code for this puzzle i dont know how the code works .give me a full explanation