Re: Simple n-tuple problem - with no simple solution
- To: mathgroup at smc.vnet.net
- Subject: [mg115799] Re: Simple n-tuple problem - with no simple solution
- From: Leonid Shifrin <lshifr at gmail.com>
- Date: Fri, 21 Jan 2011 04:30:43 -0500 (EST)
If I understood the problem correctly, here is what I would do: In[67]:= n = 2; N[IntegerPartitions[20, {n}]/20] Out[68]= {{0.95, 0.05}, {0.9, 0.1}, {0.85, 0.15}, {0.8, 0.2}, {0.75, 0.25}, {0.7, 0.3}, {0.65, 0.35}, {0.6, 0.4}, {0.55, 0.45}, {0.5, 0.5}} Regards, Leonid On Thu, Jan 20, 2011 at 2:33 PM, Don <donabc at comcast.net> 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? > > Thank you. > >