Skip to content

sys-git/towers

Repository files navigation

#TOWERS of Hanoi for Python

Author

Build Status Coverage Status Documentation Status PyPI version PyPI PyPI PyPI PyPI Updates Python 3

Towers of Hanoi algorithm in a useful form.

##Example

    >>> tower = Towers(height=3)
    >>> print(tower)
    Towers(Rods(3 - start([***, **, *]), end([]), tmp([])))
    >>> print('moves required: {moves}'.format(moves=tower.moves_for_height(height)))
    moves required: 7
    >>> with tower:
    ...    for i in tower:
    ...        print(i)
    Move(disk=*, start=Rod(name='start', disks=[***, **, *], height=3), end=Rod(name='end', disks=[], height=3), moves=0)
    Move(disk=**, start=Rod(name='start', disks=[***, **], height=3), end=Rod(name='tmp', disks=[], height=3), moves=1)
    Move(disk=*, start=Rod(name='end', disks=[*], height=3), end=Rod(name='tmp', disks=[**], height=3), moves=2)
    Move(disk=***, start=Rod(name='start', disks=[***], height=3), end=Rod(name='end', disks=[], height=3), moves=3)
    Move(disk=*, start=Rod(name='tmp', disks=[**, *], height=3), end=Rod(name='start', disks=[], height=3), moves=4)
    Move(disk=**, start=Rod(name='tmp', disks=[**], height=3), end=Rod(name='end', disks=[***], height=3), moves=5)
    Move(disk=*, start=Rod(name='start', disks=[*], height=3), end=Rod(name='end', disks=[***, **], height=3), moves=6)
    >>> print(tower)
    Towers(Rods(3 - start([]), end([***, **, *]), tmp([])))
    >>> print('moves taken: {moves}'.format(moves=tower.moves))
    moves taken: 7

##To install

    $ pip install towers

##Build documentation

    $ make sphinx-html