Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

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/


  • 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.