Towers of Hanoi: Difference between revisions
Content deleted Content added
→Python recursive II: Pylinted, added works with tag, updated output |
|||
Line 3,431:
Or, separating the definition of the data from its display:
{{Works with|Python|3.7}}
<lang python>'''Towers of Hanoi'''
Line 3,438:
def hanoi(n):
'''A list of (from, to) label pairs,
where a, b and c are labels for each of the
def go(n, a, b, c):
p = n - 1
Line 3,457:
return x.rjust(5, ' ') + ' -> ' + y
print(__doc__ + ':\n\n' + '\n'.join(
map(fromTo, hanoi(4)('left')('right')('mid'))
))</lang>
{{Out}}
<pre>Towers
left -> mid
left -> right
mid -> right
|