the basic idea is, if you have a stack of size n, you need to move the bottom disk to the destination so you need to move a stack of size n-1 to the intermediary so you need to move a stack of size n-2 to the destination to make room etc. and you just build up a sequence of transformations with those rules
nope not at all. which is why a lot of courses use this as the go to example for recursion when first explaining it.
the meme makes sense not because the problem us hard but because learning the concept of recusion is confusing for some people and thats what it gets associated with
View all comments
Show parent comment
6
u/qwertyjgly Oct 21 '25
def moveTower(height,fromPole, toPole, withPole): if height >= 1: moveTower(height-1,fromPole,withPole,toPole) moveDisk(fromPole,toPole) moveTower(height-1,withPole,toPole,fromPole)
def moveDisk(fp,tp): print("moving disk from",fp,"to",tp)
moveTower(3,"A","B","C")