Here’s my code:
this.detonate = function(i) { this.say("Detonate " + i, [i]); };
var coins = this.getItems();
var values = [];
for (var i = 2; i <= 120; ++i)
{
values.push(i);
}
this.isPrime = function(v)
{
for (var j = 0; j < values.length; ++j)
{
if (v === values[j])
{
return true;
}
else if ((v / values[j]) % 1 === 0)
{
return false;
}
}
return true;
};
for (var i = 0; i < values.length; ++i)
{
if (this.isPrime(values[i]) === false)
{
this.detonate(values[i]);
}
}
this.say("Woohoo, safe! Lootin' time!"); // (do not remove)
this.move(coins[0].pos);
If I check that my number is not a prime with the function it will drop multiple ogres in the same location. Because it drops several ogres in the same spot, the whole simulation takes longer than allocated (around mine 96 at the 7:30 minute mark). If I move the prime code from the function inside the for loop everything works as expected (one ogre per mine).
Code that works:
this.detonate = function(i) { this.say("Detonate " + i, [i]); };
var coins = this.getItems();
var values = [];
for (var i = 2; i <= 120; ++i)
{
values.push(i);
}
for (var i = 0; i < values.length; ++i)
{
var prime = true;
for (var j = 0; j < values.length; ++j)
{
if (values[i] === values[j])
{
break;
}
else if ((values[i] / values[j]) % 1 === 0)
{
prime = false;
break;
}
}
if (prime === false)
{
this.detonate(values[i]);
}
}
this.say("Woohoo, safe! Lootin' time!"); // (do not remove)
this.move(coins[0].pos);