r""" Python module for OEIS sequence number A048992. Hannah Rollman's numbers: the numbers excluded from A048991. Examples of use. ----------------------------------------------------------------------- >>> from a048992 import * >>> print a048992_list(12) [12, 23, 31, 34, 41, 42, 45, 51, 52, 53, 56, 61] >>> print a048992_offset 1 >>> for x in a048992_list_pairs(6): ... print x ... (1, 12) (2, 23) (3, 31) (4, 34) (5, 41) (6, 42) >>> print a048992_list_upto(41) [12, 23, 31, 34, 41] >>> print a048992(5) 41 ----------------------------------------------------------------------- """ from itertools import islice, izip, takewhile, count __all__ = ('a048992_offset', 'a048992_list', 'a048992_list_pairs', 'a048992_list_upto', 'a048992', 'a048992_gen') __author__ = 'Nick Hobson ' a048992_offset = offset = 1 def a048992_gen(): """Generator function for OEIS sequence A048992.""" st = '' for n in count(1): t = str(n) if st.find(t) == -1: st += t else: yield n def a048992_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(a048992_gen(), n)) def a048992_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), a048992_gen())) def a048992_list_upto(m): """Returns a list of all terms not exceeding m > 0.""" if m < 1: raise ValueError, 'Input must be a positive integer' return list(takewhile(lambda t: t <= m, a048992_gen())) def a048992(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(a048992_gen(), n-offset, n-offset+1)).pop()