The Descent - Puzzle discussion


#257

Hello
i am new here
and i am trying to solve this problem
using C#
that is my code
i tested it on Visual Studio Console
and working good
but here
it doesn’t work
what is wrong
thanks
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)
    {

     // game loop
    

    while(true)
    {
    Mountain x = new Mountain();
    x.Get_Highest();
    Console.ReadLine();
    }
    }
    }
    public class Mountain
    {
    List Height = new List();
    public void Get_Highest()
    {
    for (int i = 0; i < 8; i++)
    {
    int mountainH = int.Parse(Console.ReadLine()); // represents the height of one mountain
    Height.Add(mountainH);
    }
    while (Height.Count >0)
    {
    for (int i = 0; i < Height.Count; i++)
    {

               if (Height[i] == Height.Max())
               {
                   Console.WriteLine(Height[i]);
                   Height.Remove(Height[i]);
               }
         
       }
       }
    

    }
    }


#258

Why is it telling me I have 0% progress even though I successfully beat all of the 6 prompts? I’m using python, not sure if that has anything to do with it… but when I would move on to the next challenge, I’d get a box with a (!) in it. Am I supposed to leave the previous commands in the code? Maybe with (#)s, so it doesn’t actually try to run that many lines of code before getting to the part that relates to the current challenge…
Thank you in advance for any and all replies!


#259

Your code must be generic enougth to beat all the challenge without any code change. If you change something, you need to beat all the challenge again.


#260

Okay, i am at the very beginning of coding , so please, explain me how i can make a different loop for every stage of the game without needing to delete the old one? I am trying to learn JavaScript.


#261

The standard approach to a puzzle (at least for me) is:
Analyze the input.

Thankfully, the IDE gives you a working stub for this.
for JS it is

 while (true) {
     for (let i = 0; i < 8; i++) {
         const mountainH = parseInt(readline());
     }
 }

As you can see, all the basic input loops are already in place. Add a simple “printErr (mountainH);” to the inner loop and watch what comes out of it for different test cases.

The two loops in this example are

    while (true)  

which loops over every turn, and

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

which loops over each of the eight mountains.

For this basic puzzle, you do not need another loop, if you don’t want to.