Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
User Journal

Journal obtuse's Journal: prime numbers, increment & interval

RE prime numbers not so random story. Of course they tend toward a pattern. Primes are defined by the patterns they don't fit. Maybe these guys are onto something, but I think not. Anyway, I hacked up this Perl script to generate first thousand or so primes, displays the increment (difference in successive primes) interval (difference in successive increments) and total, since Kumar says that the intervals tend to be equal & opposite amounts in succession. Maybe I'll make this produce an ascii graph, or maybe I'll go to bed & remove the code in the morning. I'm embarassed for anyone to see this code that I hacked out of something I grabbed off the web. Attribution would be more insulting than anonymity. Besides, I can't find it again now. Anything good isn't mine. I plead insomnia & 3:30 am.
#!/usr/bin/perl
#$ID=increminterval.pl

use strict;
use integer;

my $NUM = ($ARGV[0] 1) ? 1 : $ARGV[0];
my @flags = ();
while ($NUM--) {
        # previous is previous prime,
        my $previous = 1;
        # increment is distance between primes
        my $increment = 1;
        # previous increment amount
        my $prevIncr = 1;
        # interval is distance between increments
        my $interval = 0;
        # sum is interval running sum, by Kumar's argument, should remain quite low
        my $sum = 0;

        my @flags = (0 .. 8192);
        for my $prime (2 .. 8192 ) {
                next unless defined $flags[$prime];
                # remove all multiples of prime
                $increment = $prime - $previous;
                print "Prime $prime ";
                my $k = $prime;
                undef $flags[$k] while (($k+=$prime) 8193);
                print "Increment ($increment) ";
                $interval = $increment - $prevIncr;
                print "Interval $interval ";
                $sum += $interval;
                print "Total $sum \n";
                $prevIncr = $increment;
                $previous = $prime;
        }
}

Suggest you just sit there and wait till life gets easier.

Working...