""" Towers of Hanoi basic problem with 3 pegs.
"""


def move(n, src, dest, aux):
    """ Recursive function to solve the 3-peg Towers of Hanoi problem.

    The first recursive call moves n-1 discs from the source to the auxiliary,
    so that they are out of the way.
    Next, we move the remaining (largest) disc from the source peg to the
    destination peg.
    The second recursive call moves the n-1 discs that we left on the
    auxiliary peg, to the destination peg.

    @param int n: number of discs
    @param list src: source peg to move all the discs from
    @param list dest: destination peg to move all the discs to
    @param list aux: auxiliary peg
    @rtype: None
    """
    if n > 0:
        # Move n-1 discs from source to auxiliary, so they are out of the way.
        # Peg aux is the target of this move, while dest will be used
        # as an auxiliary here.
        move(n-1, src, aux, dest)

        # Move the remaining (n-th, largest) disc from source src to target dest
        dest.append(src.pop())

        # Display our progress
        print(A, B, C, '==============', sep='\n')

        # Move the n-1 disks that we left on auxiliary onto target.
        # Peg aux is the source of what we're trying to move, while dest
        # will be the target, and src is used as an auxiliary peg.
        move(n-1, aux, dest, src)


if __name__ == '__main__':
    import doctest
    doctest.testmod()

    # A = [5, 4, 3, 2, 1]   ==> try it with 5 discs
    A = [3, 2, 1]
    B = []
    C = []
    # initiate call from source A to target C with auxiliary B
    # move(5, A, C, B)     ==> try it with 5 discs
    move(3, A, C, B)
