MathGroup Archive 2002

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

Search the Archive

Iterators

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32894] Iterators
  • From: "Juan" <erfa11 at hotmail.com>
  • Date: Mon, 18 Feb 2002 05:22:19 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Thanks for helping me.The idea of Thomas Burton is good enough.
I write down what is the problem:
The function LL[n,s,x] returns the partitions of n in s parts with number in 
a list defined before.
LL is without Off[part::pspec], and LLL is with it.

In[5]:=LL[n_, s_, x_List] :=
   Module[{a = Array[p, s, 0], w, v, r, d, q, t, sol, m = Length[x]},
   p[0] = 1;
   w = Table[r[[p[i]]], {i, s - 1}];
   v = Flatten[{w, n - Plus @@ w}]; r = Union[x];
   d = Last[Position[r, _?(#1 < n/s & )]][[1]];
   q = Table[If[d + i > m, m, d + i], {i, s - 1}];
   t = Table[{p[i], p[i - 1], q[[i]]}, {i, s - 1}];
   sol = Flatten[Table[v, Evaluate[Sequence @@ t]], Abs[s - 2]];
   Select[sol, MemberQ[x, Last[#1]] && Last[#1] == Max[#1] & ]]

In[6]:=LL[19, 3, {1, 3, 4, 6, 8, 9}]
Part::pspec:Part specification p[1] is neither an integer nor a list of 
integers.
Part::pspec:Part specification p[2] is neither an integer nor a list of 
integers.
Out[6]={{1, 9, 9}, {3, 8, 8}, {4, 6, 9}}
Part::"pspec":"Part specification \!\(p[1]\) is neither an integer nor a 
list of integers."
Part::"pspec":"Part specification \!\(p[2]\) is neither an integer nor a 
list of integers."

In[7]:=LLL[n_, s_, x_List] :=
   Module[{a = Array[p, s, 0], w, v, r, d, q, t, sol, m = Length[x]},
   p[0] = 1;
   Off[Part::pspec];
   w = Table[r[[p[i]]], {i, s - 1}];
   v = Flatten[{w, n - Plus @@ w}];
   r = Union[x];
   d = Last[Position[r, _?(#1 < n/s & )]][[1]];
   q = Table[If[d + i > m, m, d + i], {i, s - 1}];
   t = Table[{p[i], p[i - 1], q[[i]]}, {i, s - 1}];
   sol = Flatten[Table[v, Evaluate[Sequence @@ t]], Abs[s - 2]];
   Select[sol, MemberQ[x, Last[#1]] && Last[#1] == Max[#1] & ]]

In[8]:=LLL[19, 3, {1, 3, 4, 6, 8, 9}]
Out[8]={{1, 9, 9}, {3, 8, 8}, {4, 6, 9}}
(Without problem)


In[9]:=
Timing[LLL[67, 7, {3, 5, 7, 11, 13, 17, 19, 13, 19, 31, 17, 19, 41, 43, 47, 
51, 59, 61}]]
Out[9]=
{0.18*Second, {{3, 3, 3, 3, 3, 5, 47}, {3, 3, 3, 3, 3, 11, 41}, {3, 3, 3, 3, 
5, 7, 43}, {3, 3, 3, 3, 5, 19, 31},
   {3, 3, 3, 3, 7, 7, 41}, {3, 3, 3, 3, 7, 17, 31}, {3, 3, 3, 3, 11, 13, 
31}, {3, 3, 3, 3, 17, 19, 19}, {3, 3, 3, 5, 5, 5, 43},
   {3, 3, 3, 5, 5, 7, 41}, {3, 3, 3, 5, 5, 17, 31}, {3, 3, 3, 5, 11, 11, 
31}, {3, 3, 3, 5, 17, 17, 19}, {3, 3, 3, 7, 7, 13, 31},
   {3, 3, 3, 7, 13, 19, 19}, {3, 3, 3, 7, 17, 17, 17}, {3, 3, 3, 11, 11, 17, 
19}, {3, 3, 3, 11, 13, 17, 17},
   {3, 3, 3, 13, 13, 13, 19}, {3, 3, 5, 5, 5, 5, 41}, {3, 3, 5, 5, 7, 13, 
31}, {3, 3, 5, 5, 13, 19, 19}, {3, 3, 5, 5, 17, 17, 17},
   {3, 3, 5, 7, 7, 11, 31}, {3, 3, 5, 7, 11, 19, 19}, {3, 3, 5, 7, 13, 17, 
19}, {3, 3, 5, 11, 11, 17, 17},
   {3, 3, 5, 11, 13, 13, 19}, {3, 3, 5, 13, 13, 13, 17}, {3, 3, 7, 7, 11, 
17, 19}, {3, 3, 7, 7, 13, 17, 17},
   {3, 3, 7, 11, 11, 13, 19}, {3, 3, 7, 11, 13, 13, 17}, {3, 3, 11, 11, 11, 
11, 17}, {3, 3, 11, 11, 13, 13, 13},
   {3, 5, 5, 5, 5, 13, 31}, {3, 5, 5, 5, 7, 11, 31}, {3, 5, 5, 5, 11, 19, 
19}, {3, 5, 5, 5, 13, 17, 19}, {3, 5, 5, 7, 11, 17, 19},
   {3, 5, 5, 7, 13, 17, 17}, {3, 5, 5, 11, 11, 13, 19}, {3, 5, 5, 11, 13, 
13, 17}, {3, 5, 7, 7, 7, 7, 31}, {3, 5, 7, 7, 7, 19, 19},
   {3, 5, 7, 7, 11, 17, 17}, {3, 5, 7, 7, 13, 13, 19}, {3, 5, 7, 11, 11, 11, 
19}, {3, 5, 7, 11, 11, 13, 17},
   {3, 5, 7, 13, 13, 13, 13}, {3, 5, 11, 11, 11, 13, 13}, {3, 7, 7, 7, 7, 
17, 19}, {3, 7, 7, 7, 11, 13, 19},
   {3, 7, 7, 7, 13, 13, 17}, {3, 7, 7, 11, 11, 11, 17}, {3, 7, 7, 11, 13, 
13, 13}, {3, 7, 11, 11, 11, 11, 13},
   {5, 5, 5, 5, 5, 11, 31}, {5, 5, 5, 5, 11, 17, 19}, {5, 5, 5, 5, 13, 17, 
17}, {5, 5, 5, 7, 7, 7, 31}, {5, 5, 5, 7, 7, 19, 19},
   {5, 5, 5, 7, 11, 17, 17}, {5, 5, 5, 7, 13, 13, 19}, {5, 5, 5, 11, 11, 11, 
19}, {5, 5, 5, 11, 11, 13, 17},
   {5, 5, 5, 13, 13, 13, 13}, {5, 5, 7, 7, 7, 17, 19}, {5, 5, 7, 7, 11, 13, 
19}, {5, 5, 7, 7, 13, 13, 17},
   {5, 5, 7, 11, 11, 11, 17}, {5, 5, 7, 11, 13, 13, 13}, {5, 5, 11, 11, 11, 
11, 13}, {5, 7, 7, 7, 7, 17, 17},
   {5, 7, 7, 7, 11, 11, 19}, {5, 7, 7, 7, 11, 13, 17}, {5, 7, 7, 11, 11, 13, 
13}, {5, 7, 11, 11, 11, 11, 11},
   {7, 7, 7, 7, 7, 13, 19}, {7, 7, 7, 7, 11, 11, 17}, {7, 7, 7, 7, 13, 13, 
13}, {7, 7, 7, 11, 11, 11, 13}}}

(This function is not finish.I have to fit q=Table[....], and
t=Table[...]; I send it yust to give you a example of the problem)
PD.You can give a hand!

Regards
Juan






_________________________________________________________________
MSN Photos es la manera más sencilla de compartir e imprimir sus fotos: 
http://photos.latam.msn.com/Support/WorldWide.aspx



  • Prev by Date: Re: Partitions
  • Next by Date: Re: Poynting symbol
  • Previous by thread: RE: Iterators
  • Next by thread: Newbie question on Unix and Mathematica. And a question about graph theory