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