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

That’s your job, it’s part of the puzzle.

How to encounter with spaceX from right?
For “Test cases 2”, I try to “fire” when spaceX has the same cell with the highest mountainH. But it “fire” twice, because when the spaceX turns to (right -> left) spaceX has same value from before.

What should I do?

You should update each turn your mountain data.

Do you mean, I’ve to initialize another variable to store the current mountainH?

Can you give a hint? ^^

Yeah, finally did it. Thanks for your preferences :smile:

I initialize two new variable:

  1. maxHeight: to store the highest mountain from mountainH
  2. highestCell: to store where the highest mountain is

I’m trying to solve this since yesterday. I’m doing this in PHP. I get stuck from the 4th stage on: i try to find the biggest mountain still inside the inside the “for $i 0 til 7 loop”. It’s not giving me the biggest mountain. in ex.4 it says its no.2 and in ex.5 it says it’s the 6.

for this, after the 1st part of the loop, but still inside i write: if mountainH > biggestmountain then biggestmountain is $i.

What am I doing wrong?

EDIT: so, so far i revised my code so many times i decided to mess with the default code to see if there’s something than can be fixed. It didn’t completely fixed but when i changed

for ($i = 0; $i < 8; $i++)

for

for ($i = 0; $i == 7; $i++)

it worked the first couple of passes. these 2 lines of code shouldn’t make any difference. I really don’t understand this.

I’ve written a solution in C#. The code seems to be correct, the debug output shows that the correct mountain will be fired upon. But the ship fires the shots late.
Could anyone verify this?

No full code allowed

why do you need 2 variables to save the same value?

You have to output FIRE or WAIT per turn not only FIRE

great game, I’ve spent 25m to read carefully the whole guide (include the synopsis) and 3m to type 7 lines of code. I’ve solve :slight_smile:

That’s the good way to work :slight_smile:

Because $i is 0 to 8 but it takes two ways back to the x=0?

im working in ruby is using a find max function for the array a good approach or am i way off?

That’s a good way to find the highest mountain but you also need the index, to fire when your ship is above it.

Can someone help me understand why this doesn’t work. It’s not full code but I have the following conditional which basically says to only fire if the mountain is right below you:

 if(mountainH == (spaceY-1))
        {
            cout << "FIRE" << endl;
        }

On the output I get:

your spaceship is over mountain 7, your altitude is 7
Height of mountain 7 : 6
Standard Output Stream:
HOLD

How can it be printing hold here? The condition is met by the read out.

Hi,
I’m checking my condition in javascript like this:

if (condition) {
    printErr('fire');
    print('FIRE');
} else {
    printErr('hold');
    print('HOLD');
}

The problem is that the ‘FIRE’ is not triggered even when I get a ‘fire’ error stream in the output console. It’s always ‘HOLD’. Is it NOT a proper way to check my condition?

PHP: mountainH is not an array? Dont know how to find biggest mountain…

echo (max($mountainH)."\n"); -> Warning: max(): When only one parameter is given, it must be an array in the answer code

Please ignore this question. This seems to be an issue due to the unnecessary loop. I checked the condition in a loop and also triggered the fire within that loop, but I should put it on the outside of the loop.