# Move the stack of peasants onto another stump.
# You can only carry 1 peasant at a time.
# You cannot stack a larger peasant onto a smaller peasant.
# You have access to the following APIs:
# pickUpItem(container) picks up the top/last item in a container.
# dropItem(container) drops the top/last (and only) item in you're carrying.
# You and the stumps have the following APIs:
# peekItem() returns the top item of the container.
# viewStack() returns an array of items in the container.
# Peasants have the following APIs:
# size; returns the size of the peasant
stump1 = hero.findByType("stump")[0] # This is where the peasants start.
stump2 = hero.findByType("stump")[1]
stump3 = hero.findByType("stump")[2]
def move(frm, to):
from_stump = [stump1, stump2, stump3][frm - 1]
to_stump = [stump1, stump2, stump3][to - 1]
hero.say("Moving from {} to {}".format(frm, to))
hero.pickUpItem(from_stump)
hero.dropItem(to_stump)
def hanoi(n, frm, to, via):
if (n == 1):
move(frm, to)
pass
else:
pass
hanoi(n - 1, frm, via, to)
move(frm, to)
hanoi(n - 1, via, to, frm)
hanoi(5, 1, 2, 3)
this line is wrong
hero.say("Moving from {} to {}".format(frm, to))
Use
hero.say("Moving from " + frm + " to " + to)
CodeCombat doesn’t support .format so you have to use this
or you can just delete the say statement
Wilwa can you stop trying to farm solutions by posting in old topics?
Sorry, I was just trying to help
It is not when you are just asking people to give you credit for a solution.
nvm, just don’t give me the solution
Yes please stop cluttering posts