r""" Python module for OEIS sequence number A036447. Double and reverse digits. Examples of use. ----------------------------------------------------------------------- >>> from a036447 import * >>> print a036447_list(12) [1, 2, 4, 8, 61, 221, 244, 884, 8671, 24371, 24784, 86594] >>> print a036447_offset 0 >>> for x in a036447_list_pairs(6): ... print x ... (0, 1) (1, 2) (2, 4) (3, 8) (4, 61) (5, 221) >>> print a036447(5) 221 ----------------------------------------------------------------------- """ from itertools import islice, izip __all__ = ('a036447_offset', 'a036447_list', 'a036447_list_pairs', 'a036447', 'a036447_gen') __author__ = 'Nick Hobson ' a036447_offset = offset = 0 def a036447_gen(): """Generator function for OEIS sequence A036447.""" x = 1 while True: yield x x = int(str(2 * x)[::-1]) def a036447_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(a036447_gen(), n)) def a036447_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), a036447_gen())) def a036447(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(a036447_gen(), n-offset, n-offset+1)).pop()