r""" Python module for OEIS sequence number A007396. Add 2, then reverse digits. Examples of use. ----------------------------------------------------------------------- >>> from a007396 import * >>> print a007396_list(16) [0, 2, 4, 6, 8, 1, 3, 5, 7, 9, 11, 31, 33, 53, 55, 75] >>> print a007396_offset 0 >>> for x in a007396_list_pairs(6): ... print x ... (0, 0) (1, 2) (2, 4) (3, 6) (4, 8) (5, 1) >>> print a007396(5) 1 ----------------------------------------------------------------------- """ from itertools import islice, izip from a003608 import a003608_gen __all__ = ('a007396_offset', 'a007396_list', 'a007396_list_pairs', 'a007396', 'a003608_gen') __author__ = 'Nick Hobson <nickh@qbyte.org>' a007396_offset = offset = 0 def a007396_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(a003608_gen(2), n)) def a007396_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), a003608_gen(2))) def a007396(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(a003608_gen(2), n-offset, n-offset+1)).pop()