# Prime Pathing Bonus(Phython)

https://codecombat.com/play/level/prime-pathing?

Code
``````# Get all your troops to the end of the path by passing over the traps.
# You can locate duds by finding the traps that have a value that is a prime number.
# Check the guide for clarification.

def Prime(number):
for i in range(2,(number**0.5)):
if number % i == 0:
return False
return True

friends = hero.findFriends()
traps = hero.findHazards()
firstRow = []
for trap in traps:
if trap.pos.y > 30 and trap.pos.x < 80:
if Prime(trap.value):
firstRow.append(trap)
for trap in firstRow:
if trap.pos.x > (hero.pos.x - 25):
hero.moveXY(trap.pos.x + 5, trap.pos.y)
hero.moveXY(trap.pos.x, trap.pos.y)
hero.moveXY(hero.pos.x - 5, hero.pos.y)
for friend in friends:
hero.command(friend, "move", {"x": trap.pos.x + 5, "y": trap.pos.y})
hero.wait(2.5)
hero.command(friend, "move", {"x": trap.pos.x, "y": trap.pos.y})
hero.command(friend, "move", {"x": trap.pos.x - 5, "y": trap.pos.y})
hero.moveXY(2, 15)
for friend in friends:
hero.command(friend, "move", {"x": 2, "y": 15})

secondtraps = []
for trap in traps:
if trap.pos.y < 30 and trap.pos.x < 80:
if Prime(trap.value):
secondtraps.append(trap)
while hero.pos.x < 75:
for trap in secondtraps:
if trap.pos.x < (hero.pos.x + 25) and trap.pos.x > hero.pos.x:
hero.moveXY(trap.pos.x - 5, trap.pos.y)
hero.moveXY(trap.pos.x, trap.pos.y)
hero.moveXY(hero.pos.x + 10, hero.pos.y)
for friend in friends:
hero.command(friend, "move", {"x": trap.pos.x - 7, "y": trap.pos.y})
hero.wait(2.5)
hero.command(friend, "move", {"x": trap.pos.x, "y": trap.pos.y})
hero.command(friend, "move", {"x": trap.pos.x + 8, "y": trap.pos.y})
beartraps = []
beartraps = hero.findByType("bear-trap")
hero.moveXY(93, 7)
for beartrap in beartraps:
if beartrap.pos.y < 30 and beartrap.pos.x < 80:
if Prime(trap.value):
beartraps.append(beartrap)
while hero.pos.x > 80:
for beartrap in beartraps:
if trap.pos.x < (hero.pos.x + 25) and trap.pos.x > hero.pos.x:
hero.moveXY(trap.pos.x , trap.pos.y + 5)
hero.moveXY(trap.pos.x, trap.pos.y)
hero.moveXY(hero.pos.x, hero.pos.y + 5)
for friend in friends:
hero.command(friend, "move", {"x": trap.pos.x, "y": trap.pos.y+ 5})
hero.wait(2.5)
hero.command(friend, "move", {"x": trap.pos.x, "y": trap.pos.y +5})
hero.command(friend, "move", {"x": trap.pos.x, "y": trap.pos.y+8})

``````

Hi I’ve been stuck on this level’s bonus for the past months and still cant get the bonus (went on other Prime Pathing topics to understand the value stuff)(I just put in some random stuff that I think logical)
also i copied some of the friend commanding cause im lazy XD