Primes by Trial Division - perl
26 September 2016
For perl5 only,
use strict; use vars qw(@primes);
All versions:
my $n = shift; my $count = 2; while (scalar(@primes) < $n) { print("$count\n"); push(@primes, $count); $count++; for ( my $i = 0 ; $i < scalar(@primes) ; $i++ ) { if ($count % $primes[$i] == 0) { $count++; $i = 0; redo; } } }