Skip to content

Instantly share code, notes, and snippets.

@caoxudong
Created July 10, 2013 10:25
Show Gist options
  • Save caoxudong/5965228 to your computer and use it in GitHub Desktop.
Save caoxudong/5965228 to your computer and use it in GitHub Desktop.
汉诺塔
#!/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