r""" Python module for OEIS sequence number A019460. Add 1, multiply by 1, add 2, multiply by 2, and so on. Examples of use. ----------------------------------------------------------------------- >>> from a019460 import * >>> print a019460_list(14) [2, 3, 3, 5, 10, 13, 39, 43, 172, 177, 885, 891, 5346, 5353] >>> print a019460_offset 0 >>> for x in a019460_list_pairs(6): ... print x ... (0, 2) (1, 3) (2, 3) (3, 5) (4, 10) (5, 13) >>> print a019460(5) 13 ----------------------------------------------------------------------- """ from itertools import islice, izip, count __all__ = ('a019460_offset', 'a019460_list', 'a019460_list_pairs', 'a019460', 'a019460_gen') __author__ = 'Nick Hobson ' a019460_offset = offset = 0 def a019460_gen(start): """Generator function for OEIS sequence A019460.""" x = start for m in count(1): yield x x += m yield x x *= m def a019460_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(2), n)) def a019460_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(2))) def a019460(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(2), n-offset, n-offset+1)).pop()