r""" Python module for OEIS sequence number A126256. Number of distinct terms in rows 0 through n of Pascal's triangle. Examples of use. ----------------------------------------------------------------------- >>> from a126256 import * >>> print a126256_list(16) [1, 1, 2, 3, 5, 7, 9, 12, 16, 20, 24, 29, 35, 41, 48, 53] >>> print a126256_offset 0 >>> for x in a126256_list_pairs(6): ... print x ... (0, 1) (1, 1) (2, 2) (3, 3) (4, 5) (5, 7) >>> print a126256(4) 5 ----------------------------------------------------------------------- """ from itertools import islice, izip, count __all__ = ('a126256_offset', 'a126256_list', 'a126256_list_pairs', 'a126256', 'a126256_gen') __author__ = 'Nick Hobson <nickh@qbyte.org>' a126256_offset = offset = 0 def a126256_gen(): """Generator function for OEIS sequence A126256.""" s = set([1]) for row in count(1): yield len(s) x = row s.add(x) for m in xrange(1, row//2 + 1): x = (x * (row - m)) / (m + 1) s.add(x) def a126256_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(a126256_gen(), n)) def a126256_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), a126256_gen())) def a126256(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(a126256_gen(), n-offset, n-offset+1)).pop()