The Descent - Puzzle discussion


#361

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?


#362

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.


#364

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))


#365

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


#366

Hi _CG_Thibaud! What do you mean?


#367

check my post in this thread 7 days ago


#368

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--;
            }
        }
    }

}

#369

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.


#370

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.


#372

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?


#373

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.


#374

thanks!! ^^


#375

How I do turn on the tutorial?


#376

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.


#377

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


#378

cin.ignore() could get and delete the “ENTER” you typed in the buffer pool.


#379

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.
}

#380

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.


#381

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


#382

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.