Sisyphus wrote:

>Hi,
>
>If I have an ordered array of odd positive integers (1,3,5,7,9,11,.....)
>it's not hard to express (in terms of n) the value of the integer at index
>position n:
>value = (2 * n) + 1
>
>Similarly, if I have an ordered array of odd positive integers that are also
>not divisible by 3 (1,5,7,11,13,17,19,23,25,29,31,35,37...) it's not hard to
>express (in terms of n) the value of the integer at index position n:
>value = (2 * n) + 1 + (int((n + 1) / 2) * 2)
>
>But what if I have an ordered array of odd positive integers that are also
>not divisible by both 3 and 5 (1,7,11,13,17,19,23,29,31,37...) ?
>For that array, I haven't yet found a way of expressing (in terms of n) the
>value of the integer at index n.
>
>Does anyone have a solution ? .... or links to a solution/discussion ?
>  
>

if you notice that the pattern of which numbers are divisible by 2,3 and
5, repeats with period 30.
and there are 8 numbers not divisible every 30, you start with 
'int(30/8*$_)+1'
and notice that
  1  7 11 13 17 19 23 29  <--- wanted numbers
  1  4  8 12 16 19 23 27   <--- int(30/8*$_)+1
  0 +3 +3 +1 +1  0  0 +2  <---- difference

then calculate a polynomial which fits the difference
by solving the matrix eq : (   sum( a[i]*x^i, i=0..7 ) = diff[x]  for x
= 0..7 )

you end up with:

my @poly=qw(-20 497 -4865 23660 -58625 65303 -18390);
sub poly { my $x= shift; my $res=0;
$res= ($res+$_)*$x for @poly;
return $res/2520;
}

printf(" %2d", int(30/8*$_)+1+poly($_%8)) for (0..20);


for 2,3,5 and 7  you would have to start with  210/48 .. and find a 48
order polynomial.

willem

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to