[Date Index]
[Thread Index]
[Author Index]
Re: Help with "If" statement within "Table"
*To*: mathgroup at smc.vnet.net
*Subject*: [mg90540] Re: Help with "If" statement within "Table"
*From*: "Jean-Marc Gulliet" <jeanmarc.gulliet at gmail.com>
*Date*: Sat, 12 Jul 2008 05:32:39 -0400 (EDT)
*References*: <g56t9c$3qo$1@smc.vnet.net> <48773D4A.9010205@gmail.com>
On Fri, Jul 11, 2008 at 4:05 PM, Diana Mecum <diana.mecum at gmail.com> wrote:
> 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, ...}
Sorry, my mistake: I did not check second sequence against OIS and I
have just realized that I completely missed the purpose of it!
Here are two functions ccp1 and ccp2 that gives the sequences A136164
and A136165, respectively.
(I might try later to check your original code and/or explain the
procedures below, but right now I am heading for a long and busy 14th
of July weekend -- The "Quatorze Juillet" or Bastille Day, i.e. the
French national holiday.)
In[1]:= ccp1[n_Integer] :=
Module[{c, p}, p = Partition[Divisors[n], 2, 1];
c = CoprimeQ[Sequence @@ #] & /@ p;
Pick[p, c] // Flatten // Union // Length]
SetAttributes[ccp1, Listable]
ccp1@Range[30]
% === {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}
ccp1[60]
Out[3]= {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}
Out[4]= True
Out[5]= 6
In[6]:= ccp2[n_Integer] := Module[{c, p},
p = Partition[Divisors[n], 3, 1, {2, 2}, 1];
Cases[p, {x_Integer, y_Integer, z_Integer} /;
CoprimeQ[y, x] && CoprimeQ[y, z] -> y] // Flatten // Union //
Length]
SetAttributes[ccp2, Listable]
ccp2@Range[30]
% === {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}
ccp2[60]
Out[8]= {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}
Out[9]= True
Out[10]= 5
Best regards,
-- Jean-Marc
>
> 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
Prev by Date:
**Re: Help with "If" statement within "Table"**
Next by Date:
**Re: Writing to an External file, ie .txt**
Previous by thread:
**Re: Help with "If" statement within "Table"**
Next by thread:
**How to replace TextListPlot ?**
| |