Last active
December 2, 2018 04:25
-
-
Save DrynnBavis/eab168f97fc929bb2f7e8bec122db7f0 to your computer and use it in GitHub Desktop.
A recursive solition to the Hanoi Towers problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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