Skip to content
This repository
branch: nqp_pct
Fetching contributors…

Cannot retrieve contributors at this time

file 46 lines (38 sloc) 0.689 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#! perl

# Copyright (C) 2004-2006, Parrot Foundation.

use strict;
use warnings;

my $i = 0;
my $max = 500;
my $i6 = 0;
my $i7;

while (1) {
    if ( &isprime1($i) ) {
        $i7 = $i;
        $i6++;
    }
    $i++;
    if ( $i == $max ) {
        last;
    }
}
printf( "N primes calculated to %d is %d\nlast is: %d\n", $max, $i6, $i7 );

sub isprime1 {
    my ($input) = @_;
    my $n;

    if ( $input < 1 ) {
        return 0;
    }
    $n = $input - 1;

    while ( $n > 1 ) {
        if ( $input % $n == 0 ) { return 0; }
        $n--;
    }
    return 1;
}

# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4:
Something went wrong with that request. Please try again.