Skip to content

Instantly share code, notes, and snippets.

@jimbog
Created May 3, 2018 22:11
Show Gist options
  • Save jimbog/f1ce850be9da14ac7e48bd42d1a4adc5 to your computer and use it in GitHub Desktop.
Save jimbog/f1ce850be9da14ac7e48bd42d1a4adc5 to your computer and use it in GitHub Desktop.
total = 0
def hanoi(n, _from, _to, _support):
global total
if n == 1:
total += 1
print 'move', n, 'from: ', _from, 'to', _to
else:
hanoi(n - 1, _from, _support, _to)
total += 1
print 'move', n, 'from: ', _from, 'to', _to
hanoi(n - 1, _support, _to, _from)
hanoi(6, 'a', 'b', 'c')
print total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment