# You need to guess the number from 1 to 999 (0 < n < 1000).
# You have 10 attempts!
# For each attempt Riddler will say if the number is less or greater.
# If the guessed number is less than your try, then a munchkin ogre appears.
# Else a scout ogre appears.
lowestPossible = 1
highestPossible = 999
word = (lowestPossible+highestPossible) / 2
while True:
# You need to defeat the enemy before the next attempt.
enemy = hero.findNearest(hero.findEnemies())
if enemy:
# "scout" is 'greater', "munchkin" is less.
# Prepare for the next attempt and wipe out the ogre.
if enemy.type == "scout":
highestPossible = word
word = (word + lowestPossible)/2
if enemy.type == "munchkin":
lowestPossible = word
word = (word+highestPossible)/2
hero.attack(enemy)
else:
# Make your next attempt and say it.
hero.say(word)
whats wrong?
@Chaboi_3000 @Gamestack @Seojin_Roy_Lee could you guys help me pls. I don’t know what is wrong.
Never mind i figured it out
Congrats on figuring out yourself.
Can someone pls help me with this level as well (javascript)
// You need to guess the number from 1 to 999 (0 < n < 1000).
// You have 10 attempts!
// For each attempt Riddler will say if the number is less or greater.
// If the guessed number is less than your try, then a munchkin ogre appears.
// Else a scout ogre appears.
var lowestPossible = 1;
var highestPossible = 999;
var guess = 500;
while (true) {
// You need to defeat the enemy before the next attempt.
var enemy = hero.findNearest(hero.findEnemies());
if (enemy) {
// "scout" is 'greater', "munchkin" is less.
// Prepare for the next attempt and wipe out the ogre.
if(enemy.type === "munchkin") {
guess -= 5;
} else {
guess += 5;
}
hero.attack(enemy);
}
else {
// Make your next attempt and say it.
hero.say(guess);
}
}
The algoritm is that the guess = lowestPossible + hightestPossible/2 (+1 the sum if the sum÷2==1) then if the guess is to small put lowestPossible = guess and if the guess is to big then hightest =guess. Do you need any more assistance at this level?
I dont understand the logic. Could you pls explain again? thx
Here put lowestPossible = guess
Here put hightestPossible = guess
After this, put hero.say(guess);
I’m gonna try and see thx
Then, try to resummit until you complete the level.
It keeps saying 500 and i lose in the end
var lowest = 1;
var highest = 999;
var guess = 500;
hero.say(guess);
while (true) {
// You need to defeat the enemy before the next attempt.
var enemy = hero.findNearest(hero.findEnemies());
if (enemy) {
// "scout" is 'greater', "munchkin" is less.
// Prepare for the next attempt and wipe out the ogre.
if(enemy.type === "munchkin") {
lowest = guess;
} else {
highest = guess;
}
hero.attack(enemy);
}
else {
// Make your next attempt and say it.
hero.say(guess);
}
}
Try resummiting. There is something strange in that regard to the level. So resummit until you succed. Let me know when you complete the level, ok?
Ok thanks for your help again. I’m gonna try rn
I don’t see where you are changing the value of ‘guess’. At the top of your code, you define it as ‘guess = 500’, but then never change it. So yes, guess is always going to be 500.
I’ve submitted 10 times. Only saying 500
Oh ok. I’ll see right now but by how much is my problem
I forgot to tell. After that, put this:
var sum = lowest + hightest;
if (sum ÷ 2 == 1){
sum += 1;
}
guess = sum / 2
Could you also pls explain the logic of that so that I’ll be more independent in my thinking in future levels? Thx
For my solution, I manipulate the high and low variables, depending on whether it’s a scout or ogre. I also have a function that defines ‘guess’, based on the values of ‘high’ and ‘low’.