MathGroup Archive 2008

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

Search the Archive

Re: Help with "If" statement within "Table"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90535] Re: [mg90500] Help with "If" statement within "Table"
  • From: "Diana Mecum" <diana.mecum at gmail.com>
  • Date: Sat, 12 Jul 2008 05:31:36 -0400 (EDT)
  • References: <200807110602.CAA03738@smc.vnet.net>

SSeziwa,

Thanks. Yes, I did initialize the list as follows. I padded the terms with
2's, and started with the 12th term.

A136164 = {0, 2, 2, 2, 2, 3, 2, 2, 2, 3, 2}
A136164 = PadRight[A136164, 1000, 2];
Table[If[CoprimeQ[Divisors[n][[j]], Divisors[n][[j - 1]]] ||
    CoprimeQ[Divisors[n][[j]], Divisors[n][[j + 1]]],
   A136164[[n]] = A136164[[n]] + 1], {j, 3, Length[Divisors[n]] - 2}];

If I execute the "If" statement outside of the table, the sequence elements
are updated. For example,

n=12
j=3
If[CoprimeQ[Divisors[n][[j]], Divisors[n][[j - 1]]] ||
  CoprimeQ[Divisors[n][[j]], Divisors[n][[j + 1]]],
 A136164[[n]] = A136164[[n]] + 1]

With this, the sequence gets updated.

Thank you for your time.

Diana M.

On Fri, Jul 11, 2008 at 7:12 AM, Sseziwa Mukasa <mukasa at jeol.com> wrote:

>
> On Jul 11, 2008, at 2:02 AM, Diana wrote:
>
>  Folks,
>>
>> I am trying to write a small program to count the number of divisors
>> of a number which have at least one coprime neighbor, and secondly the
>> number of divisors which have two coprime neighbors, (one on each
>> side).
>>
>> For example, the divisors of 60 are {1, 2, 3, 4, 5, 6, 10, 12, 15, 20,
>> 30, 60}. 6 of the divisors have at least one coprime neighbor, and 5
>> of the divisors have two coprime neighbors.
>>
>> In doing this, I have written the following statement. "n" is the
>> number for which I am calculating divisors, and "A136164" is my first
>> list, the of number of divisors in the "at least one neighbor" case.
>> For some reason, A136164 is not updating when the "If" statement is
>> executed within the "Table" statement. Can someone help me? Thanks,
>> Diana M.
>>
>> Table[If[CoprimeQ[Divisors[n][[j]], Divisors[n][[j - 1]]] ||
>>    CoprimeQ[Divisors[n][[j]], Divisors[n][[j + 1]]],
>>   A136164[[n]] = A136164[[n]] + 1,], {j, 3,
>>   Length[Divisors[n]] - 2}];
>>
>>
> Did you initialize the list A136164 to be a list at least n long first?
>
> (Debug) In[14]:= A136164=ConstantArray[0,60]
> With[{n=60},
>
> Table[If[CoprimeQ[Divisors[n][[j]],Divisors[n][[j-1]]]||CoprimeQ[Divisors[n][[j]],Divisors[n][[j+1]]],A136164[[n]]=A136164[[n]]+1,],{j,3,Length[Divisors[n]]-2}]];
> A136164
> (Debug) Out[14]=
> {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
> (Debug) Out[16]=
> {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4}
>
> There seem to be other problems with your algorithm though, it only finds 4
> coprime neighbors.
>
> Regards,
>
> Ssezi
>



-- 
Diana Does It! ~~> www.DianaDoesIt.com
Kindle Digital Editions, Math Tutoring and more ...



  • Prev by Date: Re: Help with "If" statement within "Table"
  • Next by Date: Re: Help with "If" statement within "Table"
  • Previous by thread: Re: Help with "If" statement within "Table"
  • Next by thread: Re: Help with "If" statement within "Table"