aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Manring <michael@manring>2022-06-15 00:16:42 +0700
committerMichael Manring <michael@manring>2022-06-15 00:45:00 +0700
commit496f9241a6de3b9fcaf80462658c0a4802a2dd59 (patch)
treead77f6c0bd29167495117516734bcc462a5a69ad
parent8efa86a591ea5d17a1cb3c5bd28290e0d037a98f (diff)
downloadperlweeklychallenge-club-496f9241a6de3b9fcaf80462658c0a4802a2dd59.tar.gz
perlweeklychallenge-club-496f9241a6de3b9fcaf80462658c0a4802a2dd59.tar.bz2
perlweeklychallenge-club-496f9241a6de3b9fcaf80462658c0a4802a2dd59.zip
pwc169 solution in perl
-rw-r--r--challenge-169/pokgopun/perl/ch-1.pl13
-rw-r--r--challenge-169/pokgopun/perl/ch-2.pl16
2 files changed, 29 insertions, 0 deletions
diff --git a/challenge-169/pokgopun/perl/ch-1.pl b/challenge-169/pokgopun/perl/ch-1.pl
new file mode 100644
index 0000000000..7ac35d6056
--- /dev/null
+++ b/challenge-169/pokgopun/perl/ch-1.pl
@@ -0,0 +1,13 @@
+use strict;
+use warnings;
+use Math::Prime::Util qw/is_semiprime factor/;
+#
+# By its definition, 1st Brilliant number is square of 1st prime numbers
+# => 2*2 = 4
+my ($i,$count) = (4,0);
+print($i) && $i++ && $count++;
+{
+ print ", $i" if is_semiprime($i) && eval(join(" - ", map{ length } factor $i ))==0 && $count++;
+ $i++ && redo if $count < 20;
+ print "\n";
+}
diff --git a/challenge-169/pokgopun/perl/ch-2.pl b/challenge-169/pokgopun/perl/ch-2.pl
new file mode 100644
index 0000000000..7dc4f8acfd
--- /dev/null
+++ b/challenge-169/pokgopun/perl/ch-2.pl
@@ -0,0 +1,16 @@
+use strict;
+use warnings;
+use Math::Prime::Util qw/is_prime factor gcd/;
+#
+# By its definition, 1st Achilles number is made of first two primes, their powers are greater than 1 but with gcd=1
+# => 2*2*2*3*3 = 72
+my ($i,$count) = (72,0);
+print($i) && $i++ && $count++;
+{
+ redo if is_prime $i && $i++;
+ my %factor;
+ $factor{$_}++ foreach factor $i;
+ print ", $i" if keys(%factor) > 1 && !scalar(grep{$_ < 2} values %factor) && gcd(values %factor)==1 && $count++;
+ $i++ && redo if $count < 20;
+ print "\n";
+}