# The Descent - Puzzle discussion

#192

All the puzzles here work the same. You’re given a problem statement and the skeleton of a program intended to solve it. The skeleton will read the inputs from the server and gives a (wrong) answer in the correct format. Your task is to modify the skeleton so that the answer is correct.

Several test cases are provided for each puzzle, which allows you to run your program against different inputs to check the correctness of the program. When your program can pass all the test cases, you can submit it against the validators, which are more test cases that are similar but not the same as the practice cases. You get points based on how many of the validators you pass.

One common problem is that the user doesn’t read the problem statement fully. It explains what needs to be done, what inputs will be given, and what the output is supposed to look like. It’s not obvious on some puzzles (especially if you’ve messed with the sizes of the panels), but the problem statement is right below the graphics window and is scrollable. Make sure you read it all the way to the end.

CG is a great place for self-learning if you already know a bit about programming, but it’s not really a good place to learn how to code from scratch; the barrier to entry is that you already know how to do basic things like string manipulation, arrays, conditionals (if…then), and loops.

Hope this helps.

P.S. with all that said, make sure you’re outputting the index (1-8) of the mountain you want to shoot at and not its height.

#193

ah okay, thanks, I was just going about how to do it wrong, your explanation helped a lot, thank you

#195

I solved this pretty quickly but wasn’t happy with the solution, so I tried to make it shorter but now I can’t get it to work and don’t understand why.

``````while (true) {
let heights = [];

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

print(heights.indexOf(heights.reduce((max, cur) => cur > max ? cur : max, 0)));
}``````

#196

#197

Story of my life… wish it could have said something like “readLine function does not exist”, would of been helpful >.>

Thanks.

#198

the error message is “ReferenceError: readLine is not defined” which is almost the same.
Have you seen the “console output” panel?

#199

Sorry 4 the stupid question, but i dont understand, why, if i int a variables before “while”, all crashing?

#200

And the language is?

#201

The heights of each mountain get recalculated each time you blow one up. You then get the new heights through the console. If you don’t re-read them each time (i.e. inside the while loop), you’ll be doing your calculations on the original heights of the mountain rather than the new heights, so you’ll likely hit the same mountain each time.

#202

HI,
I’m very new to coding and thought this looked like a great way to learn.
I am trying to solve this in Python 3 and have written the following code. However the ship seems to crash every time.
Can anyone tell me what I’m doing wrong?!

Thanks

Sam

``````while True:
hmax = 0
imax = 0
for i in range(8):
mountain_h = int(input())  # represents the height of one mountain.
if mountain_h > hmax:
hmax = mountain_h
imax = i
print (imax)

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

# The index of the mountain to fire on.
print("4")``````

#203

Hi…
Fixed it now. Left the Print(“4”) in there. That seems to have solved it.

Thanks
Sam

#204

this my first time playing codigames and I solve one of the cases on the game but when I change to the other case to solve it too the first I solved is delete. someone that can help me, please.

#205

You need to pass ALL testcases with the same code. Your code must be good enough to be valid in every situation.

#206

For Python3 my solving:

[it’s not the right place to post your solution.]

#207

Hello, im new to this website and python but I seem to have come across a problem. I checked the solution for descent because i couldnt figure out what I was doing wrong. The solution does not appear to target the highest mountain so how is that considered accurate and does the input even serve a purpose ? It feels like the entire program can be simplified to just printing *** (i wont post it but i feel like it should be obvious).

So after testing my idea im wrong but I dont understand why. Can I get a little info from someone that has 1: beat descent and 2: is capable with python 3 and can explain something to a complete noob.

#208

Hello my friends,
i want to share with you a sample solution of this problem.

[No solution pasting here]

#209

I don’t understand the javascript solution provided.

if the mountainH is 9 and sets the value of max to 9 then wouldn’t mountainH never be greater than max?

admin edit no need to paste code here

#210

yep. What does it mean? That “max” (=9) is actually the maximum value for the height of the mountain. The algorithm found the maximum, you just need to print the index of the highest mountain to shoot at it.

#211

So, I’m probably just being an idiot about this, but here’s my problem. I’m using Javascript, and I’m a bit confused on how the whole max and imax things work (Got them from the solution hint thing, since I was confused). I don’t really understand how they work, could anyone give me a bit of detail on it?

#212

max is the height of the tallest mountain. “The tallest mountain is [max] units high”
imax is the index of that mountain within the array. “The tallest mountain is in position [imax] in the list of mountains.”

Remember, your output is supposed to be the index of the mountain, not its height.