Skip to content

Instantly share code, notes, and snippets.

@cynovg
Last active July 30, 2017 13:24
Show Gist options
  • Select an option

  • Save cynovg/bedd2f4c361c96af20d3d59286cba3c7 to your computer and use it in GitHub Desktop.

Select an option

Save cynovg/bedd2f4c361c96af20d3d59286cba3c7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use Modern::Perl;
my @natural = separator(10_000_000);
say scalar @natural;
sub separator {
my $number = shift;
my %hash = map { $_ => 1 } 1..$number;
for ( my $i = 2; $i * $i <= $number; $i++ ) {
if ( $hash{ $i } ) {
for ( my $composite = $i * $i; $composite <= $number; $composite += $i ) {
delete $hash{$composite};
}
}
}
return sort { $a <=> $b } keys %hash;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment