Re: Generating r-combination or r-permutations with replacement.

*To*: mathgroup at smc.vnet.net*Subject*: [mg51257] Re: [mg51248] Generating r-combination or r-permutations with replacement.*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>*Date*: Sun, 10 Oct 2004 05:52:31 -0400 (EDT)*References*: <200410100557.BAA22558@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

On 10 Oct 2004, at 14:57, phil wrote: > Is there an easy function in mathematica that generates a set/list that > consists of r-combinations or r-permutations with replacement? > > e.g. I want the set of all possible sets with 3 elements, with entries > from > {1,2,3,4}, and also the set of all possible unordered sets with 3 > elements, > with entries from {1,2,3,4}. > > Any help is appreciated, > > -Philip Lu > > > 1. << DiscreteMath`Combinatorica` KSubsets[{1, 2, 3, 4}, 3] {{1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}} 2. Distribute[Table[{1, 2, 3, 4}, {3}], List] {{1, 1, 1}, {1, 1, 2}, {1, 1, 3}, {1, 1, 4}, {1, 2, 1}, {1, 2, 2}, {1, 2, 3}, {1, 2, 4}, {1, 3, 1}, {1, 3, 2}, {1, 3, 3}, {1, 3, 4}, {1, 4, 1}, {1, 4, 2}, {1, 4, 3}, {1, 4, 4}, {2, 1, 1}, {2, 1, 2}, {2, 1, 3}, {2, 1, 4}, {2, 2, 1}, {2, 2, 2}, {2, 2, 3}, {2, 2, 4}, {2, 3, 1}, {2, 3, 2}, {2, 3, 3}, {2, 3, 4}, {2, 4, 1}, {2, 4, 2}, {2, 4, 3}, {2, 4, 4}, {3, 1, 1}, {3, 1, 2}, {3, 1, 3}, {3, 1, 4}, {3, 2, 1}, {3, 2, 2}, {3, 2, 3}, {3, 2, 4}, {3, 3, 1}, {3, 3, 2}, {3, 3, 3}, {3, 3, 4}, {3, 4, 1}, {3, 4, 2}, {3, 4, 3}, {3, 4, 4}, {4, 1, 1}, {4, 1, 2}, {4, 1, 3}, {4, 1, 4}, {4, 2, 1}, {4, 2, 2}, {4, 2, 3}, {4, 2, 4}, {4, 3, 1}, {4, 3, 2}, {4, 3, 3}, {4, 3, 4}, {4, 4, 1}, {4, 4, 2}, {4, 4, 3}, {4, 4, 4}} Andrzej Kozlowski Chiba, Japan http://www.akikoz.net/~andrzej/ http://www.mimuw.edu.pl/~akoz/

**References**:**Generating r-combination or r-permutations with replacement.***From:*"phil" <enfo@ucla.edu>