The Descent - Puzzle discussion

Because you break (out of the while true loop) and cannot reach the next round.

thankā€™s iā€™m so stupid ^^

Hello there, just finished up the Defibrillators puzzle, and looking to continue with the Descent, but the Tab and Ctrl keys seems to be ineffective nowā€¦ like, theyā€™re still working on my computer, but they donā€™t have any effect on the computer integrated IDEā€¦
Anyone experienced that issue before ?

EDIT: Seems like I was in EMACS configuration instead of Classic in the parameters, no idea how it got like that, but anyway, problem seems to be solved

import sys
import 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.

mts = []
# game loop
while True:
    for i in range(8):
        mountain_h = int(input())  # represents the height of one mountain.
        mts.append(mountain_h)
        mts.sort()
        print(len(mts) - 1)

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

    # The index of the mountain to fire on.

I donā€™t understand why this would not work. The largest mountain is immediately sorted to the end and printed.

You are asked to output the index of the highest mountain. If you sort the mountains, the original order is lost so the index becomes wrong.

A post was merged into an existing topic: How do i learn to program? HELP ME PLEASE :slight_smile:

can you explain what you did here

can someone explain what i did wrong here
while true; do
target= 9
fire= 0
for (( i=0; i<8; i++ )); do
# mountainH: represents the height of one mountain.
read - mountainH
if({$mountainH < $target}; echo ā€œ$mountainHā€); then
$mountainH= $i
$i= $fire
done
done
echo ā€œ$fireā€

Only one echo, not more.

First time user to the site. Itā€™s annoying that I was failing for have extra console.logs. I use them to iterate and test resultsā€¦ and spent 15 minutes completely puzzled as to why my code wasnā€™t working.

I love the site and the concept behind it, but sometimes there is a just a lot of information displayed at once.

For javascript, use
console.error()
to display debug messages for yourself.

console.log() is for solution output.

Hi, I am actually trying to solve it with JS code.

But while debugging my code i found that the mountain height value changed as it continue to itterate.

Here are the initial height of the mountain and the last itteration before error message.

INITIAL
Height of mountain 0 : 0
Height of mountain 1 : 6
Height of mountain 2 : 7
Height of mountain 3 : 5
Height of mountain 4 : 0
Height of mountain 5 : 8
Height of mountain 6 : 1
Height of mountain 7 : 0

LAST ITTERATE BEFORE ERROR

Height of mountain 0 : 0
Height of mountain 1 : 2
Height of mountain 2 : 4
Height of mountain 3 : 3
Height of mountain 4 : 0
Height of mountain 5 : 0
Height of mountain 6 : 0
Height of mountain 7 : 0

I am completely at lost is it a bug or did i miss something ?
This happened while trying middle mountain 3 shot test.

thanks for reply
Isfaen

In each loop your code is supposed to read the latest heights of the mountains, as they change after every round. In other words, you may ignore previous roundsā€™ heights.

Can someone help me please. Here is the code wrote

    Scanner in = new Scanner(System.in);

    int imax= 0 ;

    int max=0;

    // game loop

    while (true) {

         max = 0;

        for (int i = 0; i < 8; i++) {

            int mountainH = in.nextInt(); // represents the height of one mountain, from 9 to 0.

    if(mountainH > max){

         max = mountainH;

         imax = i;                

    } // represents the height of one mountain.

        }

        System.out.println("0");

        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("8"); // The index of the mountain to fire on.

    }

}

}

Print the index of the highest mountain, not all the indices.

1 Like

Iā€™m lost. Why does this not work?

import sys
import math

# game loop
highestMountain = 0
mountainIndex = 0
while True:
    for index in range(8):
        mountain_h = int(input())
        if mountain_h > highestMountain: 
            highestMountain = mountain_h
            mountainIndex = index
    print(mountainIndex)

In IDE itā€™s working like I have been conceiving, but in puzzle my python code return strange results. Why?

import sys
import math

allmounts = []
mount_max = []

while True:
__allmounts.clear()
__mount_max.clear()
__for i in range(7):
____mount_h = input()
____allmounts.append(mount_h)
____mount_max.append(mount_h)
____mount_max.sort(reverse=True)
__print(allmounts.index(mount_max[0]))

There are 8 mountains, not 7.
By the way, you may format your code properly in the forum by using the </> button in the formatting toolbar.

2 Likes

Your code does not reset highestMountain after the first round, so it is always comparing heights with the old value of highestMountain (which is wrong for subsequent rounds).

1 Like

I keep having the same error, but i feel that i have kind of the right solution , little bit frustrating :
ā€œTimeout: your program did not write to the standard output in due time.ā€

2 Likes