r""" Python module for OEIS sequence number A002491. Smallest number of stones in Tchoukaillon (or Mancala, or Kalahari) solitaire which make use of n-th hole. Examples of use. ----------------------------------------------------------------------- >>> from a002491 import * >>> print a002491_list(15) [1, 2, 4, 6, 10, 12, 18, 22, 30, 34, 42, 48, 58, 60, 78] >>> print a002491_offset 1 >>> for x in a002491_list_pairs(6): ... print x ... (1, 1) (2, 2) (3, 4) (4, 6) (5, 10) (6, 12) >>> print a002491(5) 10 ----------------------------------------------------------------------- """ __all__ = ('a002491_offset', 'a002491_list', 'a002491_list_pairs', 'a002491') __author__ = 'Nick Hobson ' a002491_offset = offset = 1 def a002491_list(n): """Returns a list of the first n >= 0 terms of OEIS sequence A002491.""" return [a002491(i) for i in xrange(offset, n+offset)] def a002491_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(zip(xrange(offset, n+offset), a002491_list(n))) def a002491(n): """Returns the term with index n >= 1; offset 1.""" if n < offset: raise ValueError, 'Input must be an integer >= offset = ' + str(offset) x = n for i in xrange(n-1, 1, -1): x += (-x) % i return x