I tried this puzzle in Lua.
I had the exact same solution but with other variable names and it didn’t work (highestMountainH instead of max and highestMountainID instead of imax).
After some name replacements attempts and copy pasting, I found out that I can use whatever name I want for imax, but I have to use max otherwise it won’t work.
Do we have to use the variable names of the solution ?
Is that standard behaviour for all puzzles ?
How are we supposed to know which name was used ? Only mountainH was mentioned in the constraints.
Thank you in advance for your help!
EDIT: ok, half an hour later, I reloaded the page, and now it works!
I used ctrl-z and came back to the exact same code I had and it doesn’t produce errors.
Not too sure what happened.
I could use some help… I don’t know how to sole this in java script except the order of mountains to fire at but when i do that the mountains change so my order doesn’t work. Can a expert help a noob out please? If anybody is listening i need the help!
Hi! I begin now to learn about coding, but I haven’t any basis. Is there somewhere a easy introduction to the langage of Javascript?? I couldn’t even understand what i, i++ or even parseInt() should mean.
Hi! Is this site for professionals or it’s a learning site? I’m beginer and I totaly do not understand how to solve this puzzle. What commands should I know?
OK, so find a Python tutorial somewhere before trying to solve puzzles.
You have to read the input then print on the standard output your answer in order to destroy a mountain without being killed.
Hello, I am a beginner at Java and I was trying to solve this puzzle.
I got passed the descending mountains. However, once I get to the scattered mountains I am clueless.
I tried that provided solution but it doesn’t work either. This is what I have
int hmax = 0;
int imax = 0;
// game loop
while (true) {
for (int i = 0; i < 8; i++) {
int mountainH = in.nextInt(); // represents the height of one mountain.
if( mountainH > hmax){
hmax =- mountainH;
imax =+ i;
}
The solution does not have hmax=- mountainH. When I try it without the subtraction sign not even the descending mountains test case works. Any help would be appreciated!
You define imax and hmax ONE time for the first turn. So after reading the inputs, you set imax/hmax to the biggest moutain and fire it properly.
Since you don’t reset imax/hmax after firing (or before reading new input), you’ll keep firing the same mountain even if it’s not the biggest mountain anymore.
Hi, so I have a few questions on the first puzzle in c++, it goes, “for i = 0, i < 8, i++”
why isnt i initialized, what is i++?
I get that i is somehow the mountain that I am currently getting a cin for height of but, what?
why can’t i initialize the variables for highest mountain and which mountain to fire on outside of the while loop?
this is what i had:
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
class Player
{
static void Main(string[] args)
{
int HighestMountainHeight = 0;
int MountainToFire = 0;
while (true)
{
for (int i = 0; i < 8; i++)
{
int mountainH = int.Parse(Console.ReadLine()); // represents the height of one mountain.
if (mountainH > HighestMountainHeight)
{
HighestMountainHeight = mountainH;
MountainToFire = i;
}
}
Console.WriteLine(MountainToFire); // The index of the mountain to fire on.
}
}
}
First iteration of the loop, you find the highest mountain right?
Once you’ve found it, you save the height.
On the second iteration, all mountains have the same height as during the first iteration but one (the previous highest one that you shot). So, what happens with this condition:
if (mountainH > HighestMountainHeight) ?
It’s never true. Because no current mountain is higher than the previous higher mountain. Do you understand the issue?