Last active
December 25, 2015 10:59
-
-
Save rosiehoyem/6965732 to your computer and use it in GitHub Desktop.
Tower of Hanoi, Day 7
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
#Tower of Hanoi | |
# Recursive solution: | |
# http://www.sparknotes.com/cs/recursion/examples/section6.rhtml | |
def toh(n, source = 'A', temp = 'B', dest = 'C') | |
toh(n - 1, source, dest, temp) if n > 1 # move all n - 1 disks to temp pole | |
puts "Move top disc #{n}: #{source} => #{dest}." # move bottom disk to destination pole | |
toh(n - 1, temp, source, dest) if n > 1 # move all n - 1 disks to destination pole | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment