r""" Python module for OEIS sequence numbers A057166. A057166: Subtraction steps in Recaman's sequence A005132. Examples of use. ----------------------------------------------------------------------- >>> from a057166 import * >>> print a057166_list(15) [4, 8, 10, 12, 14, 16, 20, 22, 23, 25, 27, 29, 31, 35, 37] >>> print a057166_offset 1 >>> for x in a057166_list_pairs(6): ... print x ... (1, 4) (2, 8) (3, 10) (4, 12) (5, 14) (6, 16) >>> print a057166(100) 208 ----------------------------------------------------------------------- """ from itertools import islice, izip, count from a057165 import a057165_gen __all__ = ('a057166_offset', 'a057166_list', 'a057166_list_pairs', 'a057166', 'a057165_gen') __author__ = 'Nick Hobson ' a057166_offset = offset = 1 def a057166_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(a057165_gen(False), n)) def a057166_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), a057165_gen(False))) def a057166(n): """Returns the term with index n >= 1; offset 1.""" if n < offset: raise ValueError, 'Input must be an integer >= offset = ' + str(offset) return list(islice(a057165_gen(False), n-1, n)).pop()