The Descent - Puzzle discussion

When I code my first test case, and the validators is ok. If i try and code the second one I lose my completion for test case 1. Anyone knows a solution?

You should try to solve the problem in a general way, not for the specific test cases you are provided.
From your message, Iguess you hardcoded the mountains youā€™re aiming at, your solution should use the inputs given in each turn to determine which mountain to aim at.

You should also check the hints for this puzzle on the left side of the screen.

1 Like

I did but somewhat I donā€™t understand better + the fifth hint help me out to identify but I canā€™t run my code even by respecting hint #5
I get invalid syntax at line 21

21 end if

22 end for

23 print(str(imax))

This is part of pseudocode from hint #5, itā€™s need to be rewritten it according to language you use

1 Like

Hi _CG_Thibaud! What do you mean?

check my post in this thread 7 days ago

I finished Testcase1 and 2 but I realized that in case 3 has a problem about the height of these mountains.Such as when the spaceship hits mountain 2 ,we must do 2 times to break it from 7 to 4 .Could anyone give me a hint clearly?? .I have already read the hint in the game but couldnā€™t understand clearly? thatā€™s my code for case1 and 2 !! Thanks in advance!!

import java.util.*;
import java.io.*;
import java.math.*;

class Player {

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);

        int[] arr = new int[20];
        while (true) {
            for (int i = 0; i < 8; i++) {
                int mountainH = in.nextInt();
                arr[i] = mountainH ;
            }
            int Max = 0;
            for (int i = 0; i < 8; i++) {
                if (arr[i] > Max) {
                    Max = arr[i];
                }
            }
            while (Max >= 0) {
                for (int i = 0; i < 8; i++) {
                    if (arr[i] == Max) {
                        System.out.println(i);
                    }
                }
                Max--;
            }
        }
    }

}

Your solution prints every non null mountain id at every turn, and not only the highest one.

In the first two test cases, shooting on a mountain reduces its height to 0, so your first turn printing matches the expected solution.

You should try printing only one mountain id per turn.

1 Like

Hello, Iā€™m new to this website and also to C++, but I wanted to learn the language. Hereā€™s my solution, I donā€™t wanā€™t help with finding a solution as I want to suffer through this on my own, I only have a small question. But hereā€™s my code so far.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <vector>
using namespace std; 

int main()
{

// game loop
while (1) {
   int answer;
	std::vector<int> h;
    for (int i = 0; i < 8; i++) {
        // represents the height of one mountain.
        int mountain_h;
        scanf("%d", &mountain_h);
        h.insert(h.end(), mountain_h);
            while (i >= 7) {
	             answer = *max_element(h.begin(), h.end()); 
            }
    }
    // Write an action using printf(). DON'T FORGET THE TRAILING \n
    // To debug: fprintf(stderr, "Debug messages...\n");

    printf("answer\n"); // The index of the mountain to fire on.
}

return 0;
}

I get this error and Iā€™m not quite sure why, when Googling whether vectors can be used on CodinGame I didnā€™t see any objections and I even found a post that contained some helpful tips and the template the author suggesting using which also had the "include " line.

Hereā€™s my error:

/tmp/Answer.c:5:10: fatal error: vector: No such file or directory
5 | #include
| ^~~~~~~~
compilation terminated.

Any help would be appreciated, thanks.

Iā€™m still stuck with The Descent 02.

Iā€™ve been coding for a long time, except I muddled up in this one. (No bugs.) Itā€™s not really clear to me. Whyā€™d I crash on Mountain 4, if it worked on The Descent 01 (test case) and how are you supposed to land anyways?

Your ship crosses the screen and drops a bomb on one mountain (the highest, print its abscissa) then crosses the screen again a bit lower and drops another bomb and so on until it lands.

thanks!! ^^

How I do turn on the tutorial?

tutorial only exists on the onboarding puzzle: https://www.codingame.com/training/easy/onboarding

There are hints on the top left panel that can help you.

In this situation, x++ and x=x+1 do the same things I think

cin.ignore() could get and delete the ā€œENTERā€ you typed in the buffer pool.

Hey guys,
Can someone explain me the answer for this puzzle. I saw the answer below in PHP but if someone can explain with words what is happening at each loop especially when the $mountainH is lowest than $highestMountain because for me nothing happened. And I want to know if STDIN read one or several values at each loop?

while (TRUE) {
$highestMountain = 0;
$highestMountainIndex = 0;
for ($i = 0; $i < 8; $i++){
    fscanf(STDIN, "%d",$mountainH);
    if ($mountainH > $highestMountain) {
        $highestMountainIndex = $i;
        $highestMountain = $mountainH;
    }
}
echo("$highestMountainIndex\n"); // The index of the mountain to fire on.
}

Hello, could someone help the newbie here? Where do I go wrong in understanding the task? I understood that the task is to put System.out.print indexes in the right order? So my code is like this:

class Player {

public static void main(String args[]) {
    Scanner in = new Scanner(System.in);

    // game loop
    while (true) {
        for (int i = 0; i < 8; i++) {
            int mountainH = in.nextInt(); // represents the height of one mountain.
        }

        // Write an action using System.out.println()
        // To debug: System.err.println("Debug messages...");

        System.out.println("0"); // The index of the mountain to fire on.
        System.out.println("1");
        System.out.println("2");
        System.out.println("3");
        System.out.println("4");
        System.out.println("5");
        System.out.println("6");
        System.out.println("7");
        
        System.out.println("0");
        System.out.println("1");
        System.out.println("2");
        System.out.println("4");
        System.out.println("5");
        System.out.println("7");
        System.out.println("3");
        System.out.println("6");
        
        System.out.println("5");
        System.out.println("2");
        System.out.println("1");
        System.out.println("3");
        System.out.println("2");
        System.out.println("3");
        System.out.println("1");
        System.out.println("6");
        
        System.out.println("5");
        System.out.println("7");
        System.out.println("1");
        System.out.println("5");
        System.out.println("3");
        System.out.println("1");
        System.out.println("1");
        System.out.println("3");
        
        System.out.println("3");

and when I run SOUTs piece by piece (putting under comment others) - all of them are correct, but when I hit ā€œtest all casesā€ it breaks down in case 2. As I noticed - it comes back and starts to run the first portion of SOUTs instead of proceeding with the second. Why is that? What is the solution then if it doesnā€™t work this way?

Thanks in advance.

1 Like

As said in the statement the task is to print index of the highest mountain at each turn ā€¦ no more no less

1 Like

Thank you for the the answer. It was stated quite clearly, but am I not doing so with my code? In the 1st case ā€œDescending mountainsā€ 1st take - biggest is No 0 (sout(index0)). Itā€™s taken down. Then the highest left is No1 (sout(index1)) and etc., etc. till (index7). And it works. I presume, that the same should happen in case 2 ā€œScattered mountainsā€, but it is not. It comes back and executes case 1 from index0 to 7. It is not proceeding to case2 for sequence 0, 1, 2, 4, 5, 7, 3, 6 like it is written in my code. Therefore it fails in case 2 on index4.