r"""
Python module for OEIS sequence number a079051.

Recaman variation: a(0) = 0; for n >= 1, a(n) = a(n-1) - f(n) if that
number is positive and not already in the sequence, otherwise
a(n) = a(n-1) + f(n), where f(n) = floor(sqrt(n)) (A000196).

Examples of use.
-----------------------------------------------------------------------
>>> from a079051 import *
>>> print a079051_list(16)
[0, 1, 2, 3, 5, 7, 9, 11, 13, 10, 13, 16, 19, 22, 25, 28]
>>> print a079051_offset
0
>>> for x in a079051_list_pairs(6):
...     print x
...
(0, 0)
(1, 1)
(2, 2)
(3, 3)
(4, 5)
(5, 7)
>>> print a079051(3)
3
-----------------------------------------------------------------------
"""

from itertools import islice, izip, count, repeat
from a005132 import a005132_gen

__all__ = ('a079051_offset', 'a079051_list', 'a079051_list_pairs', 'a079051', 'a005132_gen')
__author__ = 'Nick Hobson <nickh@qbyte.org>'

a079051_offset = offset = 0

def a079051_list(n):
    """Returns a list of the first n >= 0 terms of OEIS sequence a079051."""
    return list(islice(a005132_gen(t for x in count() for t in repeat(x, 2*x + 1)), n))

def a079051_list_pairs(n):
    """Returns a list of tuples (n, a(n)) of the first n >= 0 terms."""
    if n < 0: raise ValueError, 'Input must be a non-negative integer'
    return list(izip(xrange(offset, n+offset), a005132_gen(t for x in count() for t in repeat(x, 2*x + 1))))

def a079051(n):
    """Returns the term with index n >= 0; offset 0."""
    if n < offset: raise ValueError, 'Input must be an integer >= offset = ' + str(offset)
    return list(islice(a005132_gen(t for x in count() for t in repeat(x, 2*x + 1)), n, n+1)).pop()