r""" Python module for OEIS sequence number A007398. Add 7, then reverse digits. Examples of use. ----------------------------------------------------------------------- >>> from a007398 import * >>> print a007398_list(15) [0, 7, 41, 84, 19, 62, 96, 301, 803, 18, 52, 95, 201, 802, 908] >>> print a007398_offset 0 >>> for x in a007398_list_pairs(6): ... print x ... (0, 0) (1, 7) (2, 41) (3, 84) (4, 19) (5, 62) >>> print a007398(5) 62 ----------------------------------------------------------------------- """ from itertools import islice, izip from a003608 import a003608_gen __all__ = ('a007398_offset', 'a007398_list', 'a007398_list_pairs', 'a007398', 'a003608_gen') __author__ = 'Nick Hobson ' a007398_offset = offset = 0 def a007398_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(7), n)) def a007398_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(7))) def a007398(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(7), n-offset, n-offset+1)).pop()