Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Low-level multichoose """ #***************************************************************************** # Copyright (C) 2007 Mike Hansen <mhansen@gmail.com> # # Distributed under the terms of the GNU General Public License (GPL) # # This code is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # The full text of the GPL is available at: # # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import absolute_import from six.moves import range
from .combinat import CombinatorialClass from sage.arith.all import binomial import sage.misc.prandom as rnd from sage.misc.superseded import deprecation
class MultichooseNK(CombinatorialClass): def __init__(self, n, k): """ TESTS::
sage: a = MultichooseNK(3,2) doctest:...: DeprecationWarning: MultichooseNK should be replaced by itertools.combinations_with_replacement See http://trac.sagemath.org/16473 for details. sage: a == loads(dumps(a)) True """ "itertools.combinations_with_replacement")
def cardinality(self): """ Returns the number of multichoices of k things from a list of n things.
EXAMPLES::
sage: MultichooseNK(3,2).cardinality() doctest:...: DeprecationWarning: MultichooseNK should be replaced by itertools.combinations_with_replacement See http://trac.sagemath.org/16473 for details. 6 """
def __iter__(self): """ An iterator for all multichoices of k things from range(n).
EXAMPLES::
sage: [c for c in MultichooseNK(3,2)] doctest:...: DeprecationWarning: MultichooseNK should be replaced by itertools.combinations_with_replacement See http://trac.sagemath.org/16473 for details. [[0, 0], [0, 1], [0, 2], [1, 1], [1, 2], [2, 2]] """ yield [] return
return else:
#Find the biggest element that can be increased
#Reset the bigger elements
def random_element(self): """ Returns a random multichoice of k things from range(n).
EXAMPLES::
sage: MultichooseNK(5,2).random_element() doctest:...: DeprecationWarning: MultichooseNK should be replaced by itertools.combinations_with_replacement See http://trac.sagemath.org/16473 for details. [0, 2] sage: MultichooseNK(5,2).random_element() [0, 1] """ |