----- Original Message ----- 
From: "willem" <[EMAIL PROTECTED]>

>
> 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
>

In the meantime I, too got around to examining differences. I compared the
numbers I wanted with the array of odd numbers and noticed a cycle of period
8 that enabled me to construct the following:

my @addon = qw(0 4 6 6 8 8 10 14);
for(0..20) {
     print $_ * 2 + 1 + $addon[$_ % 8] + int($_ / 8) * 14, " ";
}

Seems to match the ouptut that your code produces - which is probably a good
sign :-)

> 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);
>
>

Thanks for that.

Next part of the problem is how to sift out the composites (as in a sieve of
Eratosthenes) from such a list of numbers. There's a pattern to that, too -
but I haven't yet managed to get my head around it properly.

Cheers,
Rob

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

Reply via email to