Created
July 10, 2013 10:25
-
-
Save caoxudong/5965228 to your computer and use it in GitHub Desktop.
汉诺塔
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
#!/usr/bin/env python | |
import os | |
def hanoiRecursively(fromBar, intermediateBar, toBar, number): | |
if number == 1: | |
print 'move 1 from ' + fromBar + ' to ' + toBar | |
else: | |
hanoiRecursively(fromBar, toBar, intermediateBar, number - 1) | |
print 'move ' + str(number) + ' from ' + fromBar + ' to ' + toBar | |
hanoiRecursively(intermediateBar, fromBar, toBar, number - 1) | |
def hanoiNonRecursively(fromBar, intermediateBar, tobar, number): | |
pass | |
n = raw_input('Enter the number of templates:') | |
hanoiRecursively('a', 'b', 'c', int(n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment