Towers of Hanoi: Difference between revisions
Content added Content deleted
m (→{{header|Python}}: Tidying) |
|||
Line 3,422:
Or, separating the composition of the data from its display:
<lang python>'''Towers of Hanoi'''
<lang python># hanoi :: Int -> String -> String -> String -> [(String, String)]▼
def hanoi(n):
'''A list of (from, to) label pairs,
where a, b and c are labels for each of
the three Hanoi tower positions.'''
def go(n, a, b, c):
p = n - 1
Line 3,432 ⟶ 3,438:
# TEST
if __name__ == '__main__':
print(▼
'\n'.join(map(▼
▲print(
▲ '\n'.join(
hanoi(4)('left')('right')('mid')
))
)</lang>
{{Out}}
<pre> left -> mid
|