r""" Python module for OEIS sequence number A007399. Add 8, then reverse digits. Examples of use. ----------------------------------------------------------------------- >>> from a007399 import * >>> print a007399_list(15) [0, 8, 61, 96, 401, 904, 219, 722, 37, 54, 26, 43, 15, 32, 4] >>> print a007399_offset 0 >>> for x in a007399_list_pairs(6): ... print x ... (0, 0) (1, 8) (2, 61) (3, 96) (4, 401) (5, 904) >>> print a007399(5) 904 ----------------------------------------------------------------------- """ from itertools import islice, izip from a003608 import a003608_gen __all__ = ('a007399_offset', 'a007399_list', 'a007399_list_pairs', 'a007399', 'a003608_gen') __author__ = 'Nick Hobson ' a007399_offset = offset = 0 def a007399_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(8), n)) def a007399_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(8))) def a007399(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(8), n-offset, n-offset+1)).pop()