diff options
| -rwxr-xr-x | challenge-169/steve-g-lynn/perl/ch-2.pl | 49 | ||||
| -rwxr-xr-x | challenge-169/steve-g-lynn/raku/ch-2.p6 | 45 |
2 files changed, 94 insertions, 0 deletions
diff --git a/challenge-169/steve-g-lynn/perl/ch-2.pl b/challenge-169/steve-g-lynn/perl/ch-2.pl new file mode 100755 index 0000000000..de5c0a9f62 --- /dev/null +++ b/challenge-169/steve-g-lynn/perl/ch-2.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +#-- generate 1st 20 achilles numbers A where +#-- A = (a ** k) * (b ** m) * j +#-- a,b prime, k,m,j, uint +#-- and r=A**(1/p) is not a uint for p uint + +use Math::Prime::Util qw(factor); + +my ($a,@achilles); + +@achilles=(); + +A: for $a (2 .. 10000) { + my @factor = factor ($a); + + my %factor=(); + + foreach $factor (@factor){ + $factor{$factor}++; + } + + scalar (keys %factor) > 1 || next; + + foreach (keys %factor){ + ($factor{$_} < 2) && next A; + } + + for $i (2,3) { #-- check square and cube roots + #-- other powers not needed for 1st 20 + my $root = $a ** (1/$i); + ($root =~ /\./) || next A; + # $root == int($root) fails for cube roots (bad bug!) + # so use a regex instead (look for decimal point) + } + + push @achilles, $a; + @achilles >= 20 && last; +} + +foreach (sort{$a<=>$b} @achilles){ + print "$_ "; +} + +print "\n"; + + +1; + diff --git a/challenge-169/steve-g-lynn/raku/ch-2.p6 b/challenge-169/steve-g-lynn/raku/ch-2.p6 new file mode 100755 index 0000000000..4ee5763fbc --- /dev/null +++ b/challenge-169/steve-g-lynn/raku/ch-2.p6 @@ -0,0 +1,45 @@ +#!/usr/bin/raku + +#-- generate 1st 20 achilles numbers A where +#-- A = (a ** k) * (b ** m) * j +#-- a,b prime, k,m,j, uint +#-- and r=A**(1/p) is not a uint for p uint + +use Prime::Factor; + +my ($a,@achilles); + +@achilles=(); + +A: for (2 .. 10000) -> $a { + my @factor = prime-factors ($a); + + my %factor=(); + + for (@factor) -> $factor { + %factor{$factor}++; + } + + (keys %factor).elems > 1 || next; + + for (keys %factor) -> $key { + (%factor{$key} < 2) && next A; + } + + + for (2,3) -> $i { #-- check square and cube roots + #-- other powers not needed for 1st 20 + my $root = $a ** (1/$i); + + (abs($root - round($root)) > 0.00001) || next A; + # checking for integer cube roots is buggy, like perl5 + } + + push @achilles, $a; + @achilles >= 20 && last; +} + +say @achilles; + + + |
