# Prime pathing level-help(python)

``````# Get all your troops to the end of the path by passing over the mines.
# You can locate duds by finding the mines that have a value that is a prime number.
# Check the guide for clarification.
traps = hero.findByType("fire-trap")
P = []
def Primes(trap):
for div in range (2,Math.ceil(Math.sqrt(trap.value))):
if trap.value % div == 0:
return False
hero.say(trap.value)
return True
for trap in traps:
if Primes(trap):
P.append(trap)
traps2 = hero.findByType("bear-trap")
G = []
for trap2 in traps2:
if Primes(trap2):
G.append(trap2)
while True:
nearest = hero.findNearest(P)
if nearest:
hero.moveXY(hero.pos.x, nearest.pos.y)
friends = hero.findFriends()
friendIndex=0
for friend in friends:
friendIndex+=1
hero.command(friend, 'move', {"x":hero.pos.x+2,"y":hero.pos.y})
hero.wait(1)
while hero.pos.x != nearest.pos.x:
hero.move(nearest.pos)
friendIndex1=0
for friend in friends:
hero.command(friend, 'move', {"x":hero.pos.x-2,"y":hero.pos.y})
hero.wait(1)
hero.moveXY(hero.pos.x-9.6,hero.pos.y)
friendIndex2=0
for friend in friends:
friendIndex2+=1
hero.command(friend, 'move', {"x":hero.pos.x+2,"y":hero.pos.y})
hero.wait(1)
if hero.pos.x<11:
break
hero.moveXY(2, 14)
while True:
nearest = hero.findNearest(P)
if nearest:
hero.moveXY(hero.pos.x, nearest.pos.y)
friends = hero.findFriends()
friendIndex=0
for friend in friends:
friendIndex+=1
hero.command(friend, 'move', {"x":hero.pos.x+4,"y":hero.pos.y})
hero.wait(1)
while hero.pos.x != nearest.pos.x:
hero.move(nearest.pos)
friendIndex1=0
for friend in friends:
hero.command(friend, 'move', {"x":hero.pos.x-4,"y":hero.pos.y})
hero.wait(1)
hero.moveXY(hero.pos.x+9.6,hero.pos.y)
friendIndex2=0
for friend in friends:
friendIndex2+=1
hero.command(friend, 'move', {"x":hero.pos.x-4,"y":hero.pos.y})
hero.wait(1)
``````

1 Like

this variable is set to 0 twice and never used, why? Btw, the other friendIndexX seems to have no impact in the code at all, i don’t know if i’m not seeing something or they do, in fact, have no purpose in the code.

1 Like

I don’t find it.(20)
do you mean

``````friendIndex2
``````

?

1 Like

The three friendIndex variables, which do you think are their purpose in the code? does something change if you remove them and remove the +=1 from the code?

``````# Get all your troops to the end of the path by passing over the mines.
# You can locate duds by finding the mines that have a value that is a prime number.
# Check the guide for clarification.
traps = hero.findByType("fire-trap")
P = []
def Primes(trap):
for div in range (2,Math.ceil(Math.sqrt(trap.value))):
if trap.value % div == 0:
return False
return True
for trap in traps:
if Primes(trap):
P.append(trap)
traps2 = hero.findByType("bear-trap")
G = []
for trap2 in traps2:
if Primes(trap2):
G.append(trap2)
while True:
nearest = hero.findNearest(P)
if nearest:
hero.moveXY(hero.pos.x, nearest.pos.y)
friends = hero.findFriends()
for friend in friends:
hero.command(friend, 'move', {"x":hero.pos.x+2,"y":hero.pos.y})
hero.wait(1)
while hero.pos.x != nearest.pos.x:
hero.move(nearest.pos)
for friend in friends:
hero.command(friend, 'move', {"x":hero.pos.x-2,"y":hero.pos.y})
hero.wait(1)
hero.moveXY(hero.pos.x-9.6,hero.pos.y)
for friend in friends:
hero.command(friend, 'move', {"x":hero.pos.x+2,"y":hero.pos.y})
hero.wait(1)
if hero.pos.x<11:
break
hero.moveXY(2, 14)
while True:
nearest = hero.findNearest(P)
if nearest:
hero.moveXY(hero.pos.x, nearest.pos.y)
friends = hero.findFriends()
for friend in friends:
hero.command(friend, 'move', {"x":hero.pos.x+5,"y":hero.pos.y})
hero.wait(1)
while hero.pos.x != nearest.pos.x:
hero.move(nearest.pos)
for friend in friends:
hero.command(friend, 'move', {"x":hero.pos.x-5,"y":hero.pos.y})
hero.wait(1)
hero.moveXY(hero.pos.x+9.6,hero.pos.y)
for friend in friends:
hero.command(friend, 'move', {"x":hero.pos.x-5,"y":hero.pos.y})
hero.wait(1)

``````

that’s my new code but it still don’t work

1 Like

Maybe is not code problem but formula’s, if i m correct prime numbers follow the rule 6n+1 or 6n-1, starting from 5 and so on, since n is a natural number, so 6x1-1 = 5, if any of the 2 forms gives a natural number as result, then the number your trying to compare is prime.
ex: 6xN+1=11 => 6xN = 10 => N = 10/6 (not prime) /// 6xN-1=11=>6xN=12=>N=12/6=>N=2 (prime number), so if one of the formulas give a natural number as result, then in this case 11 is a prime number.

No I just don’t have enough time. 