r""" Python module for OEIS sequence number A007397. Add 5, then reverse digits. Examples of use. ----------------------------------------------------------------------- >>> from a007397 import * >>> print a007397_list(16) [0, 5, 1, 6, 11, 61, 66, 17, 22, 72, 77, 28, 33, 83, 88, 39] >>> print a007397_offset 0 >>> for x in a007397_list_pairs(6): ... print x ... (0, 0) (1, 5) (2, 1) (3, 6) (4, 11) (5, 61) >>> print a007397(5) 61 ----------------------------------------------------------------------- """ from itertools import islice, izip from a003608 import a003608_gen __all__ = ('a007397_offset', 'a007397_list', 'a007397_list_pairs', 'a007397', 'a003608_gen') __author__ = 'Nick Hobson ' a007397_offset = offset = 0 def a007397_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(5), n)) def a007397_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(5))) def a007397(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(5), n-offset, n-offset+1)).pop()