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

Thanks for the reply. I was using spaceY because after the first pass, my ship would always fire just before or just after a mountain, meaning that my spaceX variable wasn’t updating correctly. So I tried t update the spaceX variable based on whether my pass was even (moving to the right), or odd (moving to the left). That was why I wanted the modulo.

And at least in Javascript, mountainH[i] does not work.

SpaceX is update every turn. You don’t need to store all the mountain in an array, just the index of the hightest

Ok, I solved it, but I did have to create an array. I iterated the heights of all the mountains, pushed those into an array, pulled out the math.Max from that array, then pulled the indexOf the highest value. I don’t see how I could simply save the index of the highest mountain without an array.

With the iterator of the for loop :slight_smile:

I’m sorry for stupid question but HOW?

How what? :slight_smile:

I’ve done, I’ve done it…!!!=) Thanks for tips they were very useful. I just wanted to ask how i could take these tasks without using an additional array.

Each turn returns the value of each mountain’s height. Just find out which is the tallest at the start of each pass and you will be able to clear it.

I dont unterstand how this really works. I try to get the highest mountain für each altitude (10,9,…). So in the for-loop I do something like:

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.
        scanf("%d", &mountainH);
        if(mountainH > height){
            height = mountainH;
            highest = i;
        } 
      
    }

so I get the highest mountain. BUT only in altitude of 10 the Mountainnumber contains to the spaceX-coordinate. Why?
For example I have only one Mountain. This is Mountain 3. Then I do this:

if(spaceX == highest) {
        printf("FIRE\n");
    }

BUT why this is only working für altitude of 10. In all other Altitudes the Spaceship fires wrong…

It should works correctly.

I think so. But it does not.

The code that you wrote is correct for sure. The problem is somewhere else.
Lead:

  • The initialization
  • The HOLD statement

I bet on the first one.

If it only works the first turn (at altitude 10), you are probably not resetting hight. On the second turn (at altitude 9) it’s like you are looking for a mountain higher than the highest mountain of the first turn, but there isn’t any.

Got it … it was the HOLD statement. Thanks.

I believe there is something inherently incorrect with the Javascript compilation here.

I have written the following to assist my ebugging:

    if(spaceX = heightest && spaceX > 0){
    print("FIRE");
}
else{ 
    print("HOLD");
}

When spaceX is 2 and heightest which is triggered by being over the index of the mountain (index 3), the ship fires. This makes no sense, the if statement is not triggering with the correct statement.

spaceX = hightest

is an assignment, you probably don’t want to use that inside the if test.

There is a difference between =, == and ===. Here is a very usefull table for the difference between == and ===.

1 Like

I am in stuck with test case 5: “Your spaceship is over mountain 4, your altitude is 9
You tried to fire, but you cannot now. Your cannons are not fully recharged yet”.
Any ideas?

One shoot per crossing, check if you hadn’t already fire.

Thanks. I finally figure out my problems. I have checked algro again: find highest moutain with cell cooordinate same spaceX, and then shoot it first per turn.

it’s should be easy if there mountainY.