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

all height is 0 in mountainH var ?

Is it normal, that the ship fires in the round AFTER the command is given?

Hey all, Iā€™m doing this in C# and having trouble accessing the mountain hights. Iā€™d expect it to be in an array but cannot find it. Am I supposed to take it from the input? How would one do this?

here is the way to make array:

int[] mountainH = new int [8];
for (int i = 0; i < 8; i++) {
    mountainH[i] = int.Parse(Console.ReadLine());
}

but actually, you dont need an array - you can test input values in loop as if they are array:

for (int i = 0; i < 8; i++) {
    mountainH = int.Parse(Console.ReadLine());
    if (mountainH meets condition) {
        do something;
    }
}
2 Likes

Yeh , I understand that each turn MH have the value of the highest mountain, but how to know wher is situated ??

but how do you know where is situated this highest mountain ??

You have the heightsā€™ list, itā€™s enough.

let make it clear
you loop through mountain numbers with ā€œiā€, which is loop variable
you have coordinate of your ship
why it is not enough for you to remember the value of ā€œiā€ variable of highest mountain and compare it to ship coordinate?

well yeh I didnā€™t think of it thanks (y)

So, my initial solution was just calculate the diff between the current mountain height with the ship altitude and shoot down the mountain when the diff was inferior 2, for exampleā€¦ butā€¦ on test case 2, the ship never fireā€¦ This condition was never true by the game, when, in fact, at some point before crash, it was trueā€¦
Anyone knows why?

Iā€™m doing this in C++, and I am getting some real weirdness with spaceX. Iā€™m using cerr << spaceX << endl; to detect the current X value of the ship, and it works perfectly on the first pass, but when it comes around, it occupies spaceX = 7 twice, and then starts counting down, and again on the third pass, it detects the ship at spaceX = 1 when it is at X = 0, and then double counts X = 0, so that each pass is throwing my position off farther every time. I have done nothing in my code to modify spaceX, only reading it to find my current position. Iā€™m running cerr immediately after the for loop, and the only change to the for loop I made was to feed the results into an array for use to decide when to fire. Any thoughts on how I can get the code to accurately report my spaceX?

Answered my own question! I did not have ā€œHOLDā€ in an else statement, and so when I cout << ā€œHOLDā€, it would actually cause another step, and incriment spaceX in the output before the ship had actually moved. Very strange that it handled that way, but there we go. Works perfectly now.

hey. I write in C# and i have a problem.
And i have missed shots and i donā€™t know where is the problem.
Could You give me any prompt?

I read all the thread but nothing helped me out.
Basically, my algorithm tries to find the position of the highest mountain (posOfMax) to shoot, then shoot it.
Hereā€™s whatā€™s in my for loop : ( with high=0 in the initialization )

for (int i = 0; i < 8; i++) 
 {
Ā Ā Ā scanf("%d", &mountainH[i]);
Ā Ā Ā  if (mountainH[i] > high)
Ā Ā Ā Ā Ā Ā {
Ā Ā Ā Ā Ā Ā Ā Ā Ā posOfMax = i;
Ā Ā Ā Ā Ā Ā Ā Ā Ā high = mountainH[i];
Ā Ā Ā Ā Ā Ā }
 }

Then i made the if spaceX=posOfMax it will fire, and hold if else.

EDIT : so, i added the if in the for and could pass the first two tests. the 3rd and final one are wrong apparently. any ideas ? :frowning:

Doesnā€™t scanf expect a pointer?

Yes itā€™s actually scanf("%d", &mountainH[i]); it has a pointer in my code but forgot to add it here, iā€™ll correct that.

Did you use one or two equal signs in the if test expression? One equal sign is an assignment. Two equal signs is an expression.

Well, that was it. Forgot the == when rewriting :frowning: . Thanks for the help man.

Hello, here is the C# code I have written:

Edit: No full code allowed
PS: You have to output only one thing per turn, not 8ā€¦

I passed the first three test cases, but in the fourth test case, the value of ā€œheightOfTallestMountainā€ remains at 1 even though there are mountains of height 2. Would someone be so kind as to point out how I may improve my code? Thanks in advance for your help.

really? why donā€™t you use ship position anywhere?