MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

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


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/


  • Prev by Date: cross-product in cylindrical problem
  • Next by Date: Re: Re: normal distribution random number generation
  • Previous by thread: Generating r-combination or r-permutations with replacement.
  • Next by thread: Re: Generating r-combination or r-permutations with replacement.