Skip to content

Instantly share code, notes, and snippets.

@DrynnBavis
Last active December 2, 2018 04:25
Show Gist options
  • Select an option

  • Save DrynnBavis/eab168f97fc929bb2f7e8bec122db7f0 to your computer and use it in GitHub Desktop.

Select an option

Save DrynnBavis/eab168f97fc929bb2f7e8bec122db7f0 to your computer and use it in GitHub Desktop.
A recursive solition to the Hanoi Towers problem
def solve_towers(n_disks, source, dest, helper):
if n_disks == 0:
return
solve_towers(n_disks-1, source, helper, dest)
move_disks(n_disks-1, source, dest)
solve_towers(n_disks-1, helper, dest, source)
def move_disks(n_disks, source, dest):
print("Moving disk {} from {} -> {}".format(n_disks, source, dest))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment