|
[Date Index]
[Thread Index]
[Author Index]
Re: Combination List
- To: mathgroup at smc.vnet.net
- Subject: [mg78102] Re: Combination List
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Sat, 23 Jun 2007 07:02:24 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <f55qci$k58$1@smc.vnet.net> <f58bk7$6ve$1@smc.vnet.net> <f5arsg$9aq$1@smc.vnet.net> <f5dj3m$snm$1@smc.vnet.net> <f5g8ql$eie$1@smc.vnet.net>
Bruno Campanini wrote:
> "Sem" <sarner2006-sem at yahoo.it> wrote in message
> news:f5dj3m$snm$1 at smc.vnet.net...
>> Did you mean this:
>>
>> In[1]:= Tuples[Range[4],3]
>> Out[1]=
>> {{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}}
>>
>> In[2]:= Length[%]
>> Out[2]= 64
>
> Not exactly.
>
> Tuples[Range[3],2] gives:
> 1 1
> 1 2
> 1 3
> 2 1
> 2 2
> 2 3
> 3 1
> 3 2
> 3 3
>
> I need instead unique values:
> 1 1
> 1 2
> 1 3
> 2 2
> 2 3
> 3 3
>
> Bruno
So you want
In[1]:= Sort /@ Tuples[Range[3], 2] // Union
Out[1]= {{1, 1}, {1, 2}, {1, 3}, {2, 2}, {2, 3}, {3, 3}}
First we generate all tuples, then sort the individual lists in
ascending order, and remove the duplicates.
In[2]:= Tuples[Range[3], 2]
Out[2]= {{1, 1}, {1, 2}, {1, 3}, {2, 1}, {2, 2}, {2, 3}, {3, 1}, {3,
2}, {3, 3}}
In[3]:= Sort /@ %
Out[3]= {{1, 1}, {1, 2}, {1, 3}, {1, 2}, {2, 2}, {2, 3}, {1, 3}, {2,
3}, {3, 3}}
In[4]:= % // Union
Out[4]= {{1, 1}, {1, 2}, {1, 3}, {2, 2}, {2, 3}, {3, 3}}
Regards,
Jean-Marc
Prev by Date:
Re: HELP IN RECURSIVE ESTIMATION WITH MATHEMATICA
Next by Date:
Re: Simplify and Abs in version 6.0
Previous by thread:
Re: Combination List
Next by thread:
Copy and cut is unable
|