r""" Python module for OEIS sequence number A019462. Add 1, multiply by 1, add 2, multiply by 2, and so on. Examples of use. ----------------------------------------------------------------------- >>> from a019462 import * >>> print a019462_list(14) [3, 4, 4, 6, 12, 15, 45, 49, 196, 201, 1005, 1011, 6066, 6073] >>> print a019462_offset 0 >>> for x in a019462_list_pairs(6): ... print x ... (0, 3) (1, 4) (2, 4) (3, 6) (4, 12) (5, 15) >>> print a019462(5) 15 ----------------------------------------------------------------------- """ from itertools import islice, izip, count from a019460 import a019460_gen __all__ = ('a019462_offset', 'a019462_list', 'a019462_list_pairs', 'a019462', 'a019460_gen') __author__ = 'Nick Hobson ' a019462_offset = offset = 0 def a019462_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(3), n)) def a019462_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(3))) def a019462(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(3), n-offset, n-offset+1)).pop()