r""" Python module for OEIS sequence number A003608. Add 4, then reverse digits. Examples of use. ----------------------------------------------------------------------- >>> from a003608 import * >>> print a003608_list(16) [0, 4, 8, 21, 52, 65, 96, 1, 5, 9, 31, 53, 75, 97, 101, 501] >>> print a003608_offset 0 >>> for x in a003608_list_pairs(6): ... print x ... (0, 0) (1, 4) (2, 8) (3, 21) (4, 52) (5, 65) >>> print a003608(5) 65 ----------------------------------------------------------------------- """ from itertools import islice, izip __all__ = ('a003608_offset', 'a003608_list', 'a003608_list_pairs', 'a003608', 'a003608_gen') __author__ = 'Nick Hobson ' a003608_offset = offset = 0 def a003608_gen(k): """Generator function for OEIS sequence A003608.""" x = 0 while True: yield x x = int(str(x + k)[::-1]) def a003608_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(4), n)) def a003608_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(4))) def a003608(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(4), n-offset, n-offset+1)).pop()