r""" Python module for OEIS sequence number A019461. Add 1, multiply by 1, add 2, multiply by 2, and so on. Examples of use. ----------------------------------------------------------------------- >>> from a019461 import * >>> print a019461_list(14) [0, 1, 1, 3, 6, 9, 27, 31, 124, 129, 645, 651, 3906, 3913] >>> print a019461_offset 0 >>> for x in a019461_list_pairs(6): ... print x ... (0, 0) (1, 1) (2, 1) (3, 3) (4, 6) (5, 9) >>> print a019461(5) 9 ----------------------------------------------------------------------- """ from itertools import islice, izip, count from a019460 import a019460_gen __all__ = ('a019461_offset', 'a019461_list', 'a019461_list_pairs', 'a019461', 'a019460_gen') __author__ = 'Nick Hobson ' a019461_offset = offset = 0 def a019461_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(a019460_gen(0), n)) def a019461_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), a019460_gen(0))) def a019461(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(a019460_gen(0), n-offset, n-offset+1)).pop()