r"""
Python module for OEIS sequence number A005362.
Hoggatt sequence.
a(0) = 1, a(1) = 2; for n > 1,
(n+3)(n+4)(n+5)(n+6)a(n) = 6(n+1)(n+3)(n+4)(2n+5)a(n-1) +
4(n-1)n(4n+7)(4n+9)a(n-2)
Examples of use.
-----------------------------------------------------------------------
>>> from a005362 import *
>>> print a005362_list(10)
[1, 2, 7, 32, 177, 1122, 7898, 60398, 494078L, 4274228L]
>>> print a005362_offset
0
>>> for x in a005362_list_pairs(6):
... print x
...
(0, 1)
(1, 2)
(2, 7)
(3, 32)
(4, 177)
(5, 1122)
>>> a005362_list_upto(10**6)
[1, 2, 7, 32, 177, 1122, 7898, 60398, 494078L]
>>> print a005362(6)
7898
-----------------------------------------------------------------------
"""
from itertools import islice, izip, takewhile, count
__all__ = ('a005362_offset', 'a005362_list', 'a005362_list_pairs', 'a005362_list_upto', 'a005362', 'a005362_gen')
__author__ = 'Nick Hobson '
a005362_offset = offset = 0
def a005362_gen():
"""Generator function for OEIS sequence A005362."""
x, y = 1, 2
for n in count(2):
yield x
x, y = y, (6*(n+1)*(n+3)*(n+4)*(2*n+5)*y + 4*(n-1)*n*(4*n+7)*(4*n+9)*x) / ((n+3)*(n+4)*(n+5)*(n+6))
def a005362_list(n):
"""Returns a list of the first n >= 0 terms."""
if n < 0: raise ValueError, 'Input must be a non-negative integer'
return list(islice(a005362_gen(), n))
def a005362_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), a005362_gen()))
def a005362_list_upto(m):
"""Returns a list of all terms not exceeding m >= 0."""
if m < 0: raise ValueError, 'Input must be a non-negative integer'
return list(takewhile(lambda t: t <= m, a005362_gen()))
def a005362(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(a005362_gen(), n-offset, n-offset+1)).pop()