The Descent - Puzzle discussion


#148

I think I understand now, I get the initial HighestMountainHeight, but i never reset the variable, it still sees the old value for HighestMountainHeight. I moved HighestMountainHeight inside the while loop, left MountainToFire where it is and all is good now. Thanks for helping understand!


#149

Hi there! Can anyone please explain how the for loop iteration turns can be related to the index of each mounting? I mean for (int i = 0; i < 8; i++), for instance if there were left no mountains except the third one but it is the seventh turn of iteration and when we call Console.WriteLine to print i the output will be 7 but should be 3 to destroy it (for the last and the smalllest mountain is the third one). At least the solution treat it like this, except that additional variable maxi is created and equated with i.


#150

I’m not sure I understand your question.

You need to print the index of the highest of the mountain.

i represents the index of the mountain i

You just have to find which mountain i is the highest so you can store the value in ‘maxi’ and then print it.

Is it more clear?


#151

Because there are just 8 mountains. You have to specify the index of the mountain not the height of the mountain in the print statement.


#152

I just thought it would be nice to look up the unit tests, it could clear up everything, at least for me. But your service is great though!


#153

By the way, can we see the code of unit or xunit testing here like on codewars.com for instance or I have missed something?


#154

No you can’t see the validators. You can either watch the replay (if the problem have a viewer) or try to guess the data using the validator title.


#155

Anyone else have an issue in c# where the output becomes 11 randomly near the end of the game during the Scattered Mountains test? Code works perfectly until there are only 2 mountains left, mountain 3 at a height of 3 and mountain 6 at a height of 2, suddenly my output becomes 11 which of course throws an error destroying my ship… there’s no way as far as I can see, that my code could ever output above 8 because that’s the highest possible index in the array. Is this a bug or am I missing something stupid?


#156

Somewhere you have Console.WriteLine(x);. If your program outputs 11, that means somewhere your program sets x to 11.

The easiest way to find this bug is to insert a print line statement (to the error stream) at every place where your program changes x. This way you can see what goes wrong in the log.


#157

I did it, but does not work yet


#158

In begin it seemed easy goal for me, but I was wrong. Finally decided to se 2 loops - one inside another and it helped: first 2 cases are done. But there are strong mountains, so we must understand - our shot can destroy mountain not fully. Working on it now :slight_smile:

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

/**
 * The while loop represents the game.
 * Each iteration represents a turn of the game
 * where you are given inputs (the heights of the mountains)
 * and where you have to print an output (the index of the mountain to fire on)
 * The inputs you are given are automatically updated according to your last actions.
 **/
class Player {

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int max_height = 0;
        int hill_index = 0;
        int highest_hill = 0;
        int [] hills_height = new int [8] ;
        int [] hills_list = new int [8];

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

            // Write an action using System.out.println()
            
            for (int i = max_height; i > 0; i--) {
                for (int k = 0; k < 8; k++) {
                    if (hills_height [k] == i) {
                        hills_list [hill_index] = k;
                        hill_index++;
                        }
                }
            }
            
            
            

            // Printing result
            // System.out.println (highest_hill); // works
            
            for (int i = 0; i < 8; i++) {
                System.out.println (hills_list[i]);
            }
            
        }
    }
}

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

/**
 * The while loop represents the game.
 * Each iteration represents a turn of the game
 * where you are given inputs (the heights of the mountains)
 * and where you have to print an output (the index of the mountain to fire on)
 * The inputs you are given are automatically updated according to your last actions.
 **/
class Player {

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int mountain[]= new int[7];
        int big,tall;
        tall=0;
        // game loop
        while (true) 
        {
            for (int i = 0; i < 7; i++) 
            {
                mountain[i] = in.nextInt(); // represents the height of one mountain.
            }
            for(int i=0;i<8;i++)
            {
                big = mountain[0];
                for(int j =1;j<7;j++)
                {
                    if(big<mountain[j])
                    {
                    big=mountain[j];
                    tall=j;
                    }
                }
              System.out.println(tall); // The index of the mountain to fire on.
             }
        }
    }
}

I have used array to store heights of mountains instead.But it displays “Airplane crashes at mountain 1” Why so?Can anyone help?


#160

for (int i = 0; i < 7; i++)

There are 8 mountains, not 7


#162

Why doesn’t your program work?

Sorry, I had to do it.

Because of that (among other things)
/tmp/Answer.cpp: In function ‘int main()’:
/tmp/Answer.cpp:37:21: error: ‘mountainIndexToShootAt’ was not declared in this scope

Feel free to look at the historic of this thread. There is all the information you need to solve the problem by yourself.


#163

Does some one know how many people at most one private clash could contain? Thanks!


#164

wrong thread. Answer to your question: 12.


#165

Please let me know the version of the java configured for compile ?


#166

Check out the FAQ from the main menu:


#168

using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

/**

  • The while loop represents the game.

  • Each iteration represents a turn of the game

  • where you are given inputs (the heights of the mountains)

  • and where you have to print an output (the index of the mountain to fire on)

  • The inputs you are given are automatically updated according to your last actions.
    **/
    class Player
    {
    static void Main(string[] args)
    {
    //List lst = new List();
    // game loop
    int j=-1;
    while (true)
    {
    for (int i = 0; i < 8; i++)
    {
    int mountainH;
    mountainH = Convert.ToInt32(Console.ReadLine()); // represents the height of one mountain.
    if(mountainH>j)
    j=mountainH;
    }
    //Console.Error.WriteLine();
    // Write an action using Console.WriteLine()
    // To debug: Console.Error.WriteLine(“Debug messages…”);
    //int j= lst.Max();
    Console.WriteLine(j); // The index of the mountain to fire on.
    }

    }
    }

why it is giving error Invalid command sent. It should be an integer from 0 to 7. i have tried everything .its working on visual studio.


#169

You’re asked to print the index of the mountain to fire on, not its height.