Re: Simple n-tuple problem - with no simple solution

• To: mathgroup at smc.vnet.net
• Subject: [mg115844] Re: Simple n-tuple problem - with no simple solution
• From: DrMajorBob <btreat1 at austin.rr.com>
• Date: Sat, 22 Jan 2011 03:23:45 -0500 (EST)

```The range was Range[0,1,.05], not Range[0,1,.5].

For the latter range, the problem has only two solutions aside from
rearrangements.

Bobby

On Fri, 21 Jan 2011 03:29:22 -0600, Sseziwa Mukasa <mukasa at jeol.com> wrote:

> A minor error, use:
>
> Flatten[Outer[If[Plus[##]==1,{##},Sequence@@{}]&,Sequence@@Table[Range[0,1.0,0.5],{n}]],n-1]
>
> On Jan 20, 2011, at 10:04 AM, Sseziwa Mukasa wrote:
>
>>
>> On Jan 20, 2011, at 6:33 AM, Don wrote:
>>
>>> Problem: Given an n-tuple  (n >= 1). with each element  able to take
>>> on the values in
>>> Range[0, 1.0, .05] , produce all the n-tuples that sum to 1.0.
>>>
>>> The most direct way to solve this problem is to generaate all possible
>>> n-tuples and Select out all those that sum to 1.0.
>>>
>>> For example, when n = 2 :
>>>
>>> n = 2;
>>> Select[Tuples[Table[Range[0, 1.0, .05], {n}]], Total[#] == 1 &]
>>>
>>> The problem with this solution is that the number of n-tuples that are
>>> generated before the Select is used grows exponentially fast as a
>>> function
>>> of n - causing the system to run out of memory (RAM) very quickly.
>>>
>>> Is there a more memory efficient way to solve this problem that
>>> doesn't
>>> use so much memory but still is not too slow in terms of processor
>>> time?
>>
>> Use Outer
>>
>> Flatten[Outer[If[Plus[##]==1,{##},Sequence@@{}]&,Sequence@@Table[Range[0,1.0,0.5],{n}]],1]
>>
>> Regards,
>> 	Ssezi
>

--
DrMajorBob at yahoo.com

```

• Prev by Date: Re: unexpected Timing results
• Next by Date: Re: what's wrong?!!
• Previous by thread: Re: Simple n-tuple problem - with no simple solution
• Next by thread: Re: Simple n-tuple problem - with no simple solution