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

*To*: mathgroup at smc.vnet.net*Subject*: [mg90549] Re: Help with "If" statement within "Table"*From*: Bill Rowe <readnews at sbcglobal.net>*Date*: Sat, 12 Jul 2008 05:34:25 -0400 (EDT)

On 7/11/08 at 2:02 AM, diana.mecum at gmail.com (Diana) wrote: >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? I did not try to figure out why the code you posted didn't give you the desired result. But here is a way to select all of the factors that have at least one coprime neighbor. In[18]:= factors = {1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60}; In[19]:= Pick[Rest@factors, CoprimeQ @@@ Partition[factors, 2, 1], True] Out[19]= {2,3,4,5,6} And this picks out all the factors that have a coprime on either side In[20]:= Most@ Pick[factors[[3 ;;]], And @@@ Partition[CoprimeQ @@@ Partition[factors, 2, 1], 2, 1], True] Out[20]= {3,4,5} Note, I intentionally excluded 1 from these lists. If one is to be included then it should be on the first list and that means 2 should be included on the second list.