A post was merged into an existing topic: How do i learn to program? HELP ME PLEASE
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.
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.
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).
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.ā
Make sure you output the answer every time after you have read the inputs for that round, followed by a newline if needed in the language of your choice. And note that the number of rounds is greater than 1.
This was fun to do, and it was enjoyable to see the graphical representation of the finished product! Thank you for this creative coding opportunity!
I donāt know what to do I try putting more than one number in the index but then the spaceship wont move so I put 0 and it crashes on mountain one. is there something Iām doing wrong or is there a bug?
Did you read the hints? They may help you understand. You can find them by clicking the HINTS button to the left of the puzzle statement.
yes but it doesnāt say anything about it.