""" Towers of Hanoi recursive implementation """


def move_tower(n, source, target, helper):
    """
    Move the tower starting at the nth disk
    from source to target, using helper, and
    following the rules of the Towers of Hanoi game.

    @param int n: disk to move
    @param list[int] source: source peg
    @param list[int] target: target peg
    @param list[int] helper: helper peg
    """
    # what if the source has nothing to move? -> base case
    # implicit base case - no code, but nothing happens
    # when n == 0
    if n > 0:

        # move the disks on top of the nth disk out of the way
        move_tower(n-1, source, helper, target)

        # not really a good way to access those variables,
        # but just for debugging...

        # move the nth disk
        target.append(source.pop())
        print(peg1, peg2, peg3)

        # move the top disks back on top of the nth disk
        move_tower(n-1, helper, target, source)


if __name__ == '__main__':
    peg1 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
    peg2 = []
    peg3 = []
    move_tower(peg1[0], peg1, peg3, peg2)
