MathGroup Archive 2000

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

Search the Archive

Re: generating all combinations.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22423] Re: [mg22395] generating all combinations.
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Wed, 1 Mar 2000 00:40:22 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

on 2/28/00 12:55 AM, Wen-Feng Hsiao at d8442803 at student.nsysu.edu.tw wrote:

> Dear all,
> 
> I would like to generate all the combinations n-digit lists, which can
> vary between a certain range and duplications are allowed. The three
> digits with range between -2 to 2 is the following:
> 
> allcomb = 
> Table[{i, j, k}, {i, -2, 2}, {j, -2, 2}, {k, -2, 2}];
> fltcomb = Partition[Flatten[allcomb], 3];
> 
> Is there a more succinct way to do that? If I would like to expand the
> code to 10 digits, the code would looks clumsy.
> 
> Thanks for your help.
> 
> Wen-Feng
> 
> 
> 

Here is another way to do this which may be more like what you want:

Distribute[Table[Range[-2, 2], {3}], List]

You can generalize this to other cases.
-- 
Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp




  • Prev by Date: using downloaded notebooks
  • Next by Date: Re: How to solve matrix equitions -- LinearSolve?
  • Previous by thread: Re: generating all combinations.
  • Next by thread: Re: generating all combinations.