Sha256: 0312c9d37e9c1db15f1225fcbed88bfae85b4c7dbf2147066b5098a0a5983616
Contents?: true
Size: 557 Bytes
Versions: 73
Compression:
Stored size: 557 Bytes
Contents
package Sieve; use strict; use warnings; sub new { my ($class, $max) = @_; die "ArgumentError, number too small: $max" if $max < 2; bless { max => $max }, $class; } sub primes { my $self = shift; my $prime = 2; return [$prime] if $self->{max} == $prime; my @list = 3..$self->{max}; my @primes = ($prime,); while(@list > 0) { my @candidates = grep { $_ % $prime != 0 } @list; $prime = shift @candidates; push @primes => $prime; @list = @candidates; } return [@primes]; } 1;
Version data entries
73 entries across 73 versions & 1 rubygems