Tower of Hanoi
Solution: Recursion
def tower_of_hanoi(n):
# Recursive function to solve tower of hanoi
def helper(n , from_rod, to_rod, aux_rod):
# this recursion covers base cases
# move top n-1 disks to aux_rod
helper(n-1, from_rod, aux_rod, to_rod)
# move the nth disk to to_rod
print "Move disk",n,"from rod",from_rod,"to rod",to_rod
# move top n-1 disks to to_rod
helper(n-1, aux_rod, to_rod, from_rod)
helper(n, 'A', 'B', 'C')
# A, C, B are the name of rodsLast updated
