Re: AGAIN Nested while loop!!!

*To*: mathgroup at smc.vnet.net*Subject*: [mg71636] Re: AGAIN Nested while loop!!!*From*: Bill Rowe <readnewsciv at sbcglobal.net>*Date*: Sat, 25 Nov 2006 05:37:17 -0500 (EST)

On 11/24/06 at 1:17 AM, csarami at gmail.com (mumat) wrote: >I have a list of numbers >lst = Table[Random[Integer, {i, 50}], {i, 6}] >I want to write a program that if There are two numbers x, y in A >where >Mod[x^2+y^2, 5]==0 reuturn False and the pair {x,y}, otherwise >True! >For[i = 0, i < 6, For[j = i, j < 6, >If[Mod[lst[[i]]^2 + lst[[j]]^2, 3] == 0, >Return[False,{i,j}]];Break[], j++], i++] Mathematica indexing starts at 1 not 0. >While loop and nested while loops accept only one counter "i". >i=1;j=2; >While[i<6 && While[j<6 && >Mod[lst[[i]]^2+lst[[j]]^2,7]=!=0,j++];i++];{i,j} >{2,6} My approach to solving this issue would be to avoid using either For or While. The desired list of numbers can be generated using Subsets as follows In[13]:= lst=DeleteCases[Subsets[Table[Random[Integer,{1,50}],{6}],2],{}|{_}] Out[13]= {{32, 6}, {32, 10}, {32, 29}, {32, 17}, {32, 31}, {6, 10}, {6, 29}, {6, 17}, {6, 31}, {10, 29}, {10, 17}, {10, 31}, {29, 17}, {29, 31}, {17, 31}} and the desired output can be obtained by: In[14]:= If[Mod[Plus @@ (#^2), 5] == 0, {False, #}, True]&/@ lst Out[14]= {{False, {32, 6}}, True, {False, {32, 29}}, True, {False, {32, 31}}, True, True, {False, {6, 17}}, True, True, True, True, {False, {29, 17}}, True, {False, {17, 31}}} -- To reply via email subtract one hundred and four