aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-169/e-choroba/perl/ch-1.pl24
-rwxr-xr-xchallenge-169/e-choroba/perl/ch-2.pl25
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-169/e-choroba/perl/ch-1.pl b/challenge-169/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..ef863b1cbc
--- /dev/null
+++ b/challenge-169/e-choroba/perl/ch-1.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+use Math::Prime::Util qw{ factor };
+
+sub brilliant_numbers {
+ my ($tally) = @_;
+ my @brilliant_numbers;
+ my $n = 1;
+ while (@brilliant_numbers < $tally) {
+ my @f = factor(++$n);
+ push @brilliant_numbers, $n
+ if 2 == @f
+ && length($f[0]) == length($f[1]);
+ }
+ return \@brilliant_numbers
+}
+
+use Test::More tests => 1;
+
+is_deeply brilliant_numbers(20),
+ [4, 6, 9, 10, 14, 15, 21, 25, 35, 49, 121,
+ 143, 169, 187, 209, 221, 247, 253, 289, 299];
diff --git a/challenge-169/e-choroba/perl/ch-2.pl b/challenge-169/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..48e9f7c4eb
--- /dev/null
+++ b/challenge-169/e-choroba/perl/ch-2.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+use Math::Prime::Util qw{ factor gcd };
+
+sub achilles_numbers {
+ my ($tally) = @_;
+ my $n = 1;
+ my @achilles_numbers;
+ while (@achilles_numbers < $tally) {
+ my %factors;
+ ++$factors{$_} for factor(++$n);
+ next if grep $_ == 1, values %factors; # Powerful.
+
+ push @achilles_numbers, $n
+ if 1 == gcd(values %factors); # Not perfect.
+ }
+ return \@achilles_numbers
+}
+
+use Test::More tests => 1;
+is_deeply achilles_numbers(20),
+ [72, 108, 200, 288, 392, 432, 500, 648, 675, 800, 864,
+ 968, 972, 1125, 1152, 1323, 1352, 1372, 1568, 1800];