aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-06-13 18:59:23 +0100
committerGitHub <noreply@github.com>2022-06-13 18:59:23 +0100
commit88de9732bc7bb380093f090073a600e484d774c0 (patch)
tree98846f480f9976365b0dade31f0b93d19e7df359
parent3c82dec6d398663974d0bef92f318a54f74bd167 (diff)
parent434f019b5460d3cad544685f414fe2da423277b3 (diff)
downloadperlweeklychallenge-club-88de9732bc7bb380093f090073a600e484d774c0.tar.gz
perlweeklychallenge-club-88de9732bc7bb380093f090073a600e484d774c0.tar.bz2
perlweeklychallenge-club-88de9732bc7bb380093f090073a600e484d774c0.zip
Merge pull request #6261 from steve-g-lynn/branch-for-challenge-169
Branch for challenge 169
-rwxr-xr-xchallenge-169/steve-g-lynn/perl/ch-1.pl31
-rwxr-xr-xchallenge-169/steve-g-lynn/perl/ch-2.pl49
-rwxr-xr-xchallenge-169/steve-g-lynn/raku/ch-1.p622
-rwxr-xr-xchallenge-169/steve-g-lynn/raku/ch-2.p645
4 files changed, 147 insertions, 0 deletions
diff --git a/challenge-169/steve-g-lynn/perl/ch-1.pl b/challenge-169/steve-g-lynn/perl/ch-1.pl
new file mode 100755
index 0000000000..c37dfe2676
--- /dev/null
+++ b/challenge-169/steve-g-lynn/perl/ch-1.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+
+#-- generate 1st 20 brilliant numbers
+#-- product of two prime factors of same length
+
+use Math::Prime::Util qw(primes);
+
+my @brilliants = ();
+
+for $i (1,2) { # get 1 or 2 digit primes with each iteration
+ my $ra=primes(10**($i-1), 10**($i));
+
+ for $i (0 .. @$ra-1) {
+ for $j ($i .. @$ra-1) {
+ push (@brilliants,
+ $$ra[$i] * $$ra[$j] );
+ }
+ }
+}
+
+@brilliants = sort{$a <=> $b} @brilliants;
+
+foreach (0 .. 19) {
+ print $brilliants[$_]," ";
+}
+
+print "\n";
+
+
+
+
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-1.p6 b/challenge-169/steve-g-lynn/raku/ch-1.p6
new file mode 100755
index 0000000000..9042bc0854
--- /dev/null
+++ b/challenge-169/steve-g-lynn/raku/ch-1.p6
@@ -0,0 +1,22 @@
+#!/usr/bin/raku
+
+#-- generate 1st 20 brilliant numbers
+#-- product of two prime factors of same length
+
+my @brilliants = ();
+
+for (1,2) -> $i {
+ my @a = (2..1000).
+ grep(*.is-prime).
+ grep(*.Str.chars==$i);
+
+ for (0 .. @a.elems-1) -> $i {
+ for ($i .. @a.elems-1) -> $j {
+ @brilliants.append(@a[$i]*@a[$j]);
+ }
+ }
+}
+
+say @brilliants.sort.head(20);
+
+
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;
+
+
+