Jump to content

Towers of Hanoi: Difference between revisions

m
Line 3,481:
===Graphic===
 
Refactoring the version above to recursively generate a graphicsimple solutionvisualisation:
{{Works with|Python|3.7}}
<lang python>'''Towers of Hanoi'''
Line 3,519:
# showHanoi :: ([Int],[Int],[Int]) -> String
def showHanoi(tpl):
'''String representation of a stage of a Hanoi tower state.'''
 
def fullHeight(n):
Line 3,550:
# TEST ----------------------------------------------------
def main():
'''StagesVisualisation inof a Hanoi tower sequence for N discs.
'''
n = 3
print('Hanoi sequence for ' + str(3) + ' disks:\n')
print(unlines(
fmap(showHanoi)(
Line 3,654 ⟶ 3,655:
if __name__ == '__main__':
main()</lang>
<pre>Hanoi sequence for 3 disks:
<pre> **
 
<pre> **
****
******
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.