Re: Help with "If" statement within "Table"
- To: mathgroup at smc.vnet.net
- Subject: [mg90533] Re: Help with "If" statement within "Table"
- From: "Diana Mecum" <diana.mecum at gmail.com>
- Date: Sat, 12 Jul 2008 05:31:12 -0400 (EDT)
- References: <g56t9c$3qo$1@smc.vnet.net> <48773D4A.9010205@gmail.com>
Jean-Marc, This is wonderful. Thanks. I need to take a Mathematica seminar so that I can understand your function code. A couple of questions. If you have time, would you look at my Table and If statement and tell me why it is not updating the A136164 list? In my archaic way, I would like to some up with a second rendering of the sequence. Secondly, the ccp@Range[30] sequence above replicates A136164. However, the ccp[Range[30], 2] list does not match A136165, which looks as follows. Could you take a look? {1,2,2,1,2,2,2,1,1,2,2,3,2,2,2,1,2,2,2,1,2,2,2,3,1,2,1,1,2,4, ...} Thanks, Diana On Fri, Jul 11, 2008 at 4:00 AM, Jean-Marc Gulliet < jeanmarc.gulliet at gmail.com> wrote: > 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. >> > > <snip> > > I give you a functional approach to achieve what you are looking for. The > function ccp (count coprimes} works with one and two coprime neighbors and > can be easily modified to compute many of the integer sequences related to > A136164 [1]. > > ccp[n_Integer, neighbors_: 1] := > Module[{c, p}, > p = Partition[Divisors[n], neighbors + 1, 1]; > c = CoprimeQ[Sequence @@ #] & /@ p; > Pick[p, c] // Flatten // Union // Length > ] > > SetAttributes[ccp, Listable] > > ccp@Range[30] > ccp[60] > ccp[Range[30], 2] > ccp[60, 2] > > {0, 2, 2, 2, 2, 3, 2, 2, 2, 3, 2, 4, 2, 3, 3, 2, 2, 3, 2, 4, \ > 3, 3, 2, 4, 2, 3, 2, 4, 2, 5} > > 6 > > {0, 0, 0, 0, 0, 3, 0, 0, 0, 3, 0, 3, 0, 3, 3, 0, 0, 3, 0, 0, \ > 3, 3, 0, 3, 0, 3, 0, 0, 0, 4} > > 5 > > [1] A136164, *The On-Line Encyclopedia of Integer Sequences*, > "a(n) = the number of divisors of n that are each coprime to the previous > or the following divisor of n." > > http://www.research.att.com/~njas/sequences/A136164<http://www.research.att.com/%7Enjas/sequences/A136164> > > Regards, > -- Jean-Marc > -- Diana Does It! ~~> www.DianaDoesIt.com Kindle Digital Editions, Math Tutoring and more ...