Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/Unprimeable-numbers/Perl/unprimeable-numbers.pl
Normal file
30
Task/Unprimeable-numbers/Perl/unprimeable-numbers.pl
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use feature 'say';
|
||||
use ntheory 'is_prime';
|
||||
use enum qw(False True);
|
||||
|
||||
sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r }
|
||||
|
||||
sub is_unprimeable {
|
||||
my($n) = @_;
|
||||
return False if is_prime($n);
|
||||
my $chrs = length $n;
|
||||
for my $place (0..$chrs-1) {
|
||||
my $pow = 10**($chrs - $place - 1);
|
||||
my $this = substr($n, $place, 1) * $pow;
|
||||
map { return False if $this != $_ and is_prime($n - $this + $_ * $pow) } 0..9;
|
||||
}
|
||||
True
|
||||
}
|
||||
|
||||
my($n, @ups);
|
||||
do { push @ups, $n if is_unprimeable(++$n); } until @ups == 600;
|
||||
say "First 35 unprimeables:\n" . join ' ', @ups[0..34];
|
||||
printf "\n600th unprimeable: %s\n", comma $ups[599];
|
||||
|
||||
map {
|
||||
my $x = $_;
|
||||
while ($x += 10) { last if is_unprimeable($x) }
|
||||
say "First unprimeable that ends with $_: " . sprintf "%9s", comma $x;
|
||||
} 0..9;
|
||||
Loading…
Add table
Add a link
Reference in a new issue