aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-158/e-choroba/perl/ch-1.pl24
-rwxr-xr-xchallenge-158/e-choroba/perl/ch-2.pl26
2 files changed, 50 insertions, 0 deletions
diff --git a/challenge-158/e-choroba/perl/ch-1.pl b/challenge-158/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..f565667695
--- /dev/null
+++ b/challenge-158/e-choroba/perl/ch-1.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental 'signatures';
+
+use List::Util qw{ sum };
+use Math::Prime::Util qw{ is_prime nth_prime };
+
+sub additive_primes ($n) {
+ my @ap;
+ my $i = 0;
+ while (1) {
+ my $p = nth_prime(++$i);
+ last if $p > $n;
+
+ push @ap, $p if is_prime(sum(split //, $p));
+ }
+ return \@ap
+}
+
+use Test::More tests => 1;
+is_deeply additive_primes(100),
+ [2, 3, 5, 7, 11, 23, 29, 41, 43, 47, 61, 67, 83, 89],
+ 'Example';
diff --git a/challenge-158/e-choroba/perl/ch-2.pl b/challenge-158/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..b64a65a9eb
--- /dev/null
+++ b/challenge-158/e-choroba/perl/ch-2.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+use experimental 'signatures';
+use Math::Prime::Util qw{ is_prime };
+
+sub cuban_primes ($n) {
+ my @c;
+ my $y = 0;
+ while (1) {
+ # centered hexagonal number
+ my $chn = 3 * $y * $y + 3 * $y + 1;
+ last if $chn > $n;
+
+ push @c, $chn if is_prime($chn);
+ ++$y;
+ }
+ return \@c
+}
+
+use Test::More tests => 1;
+
+is_deeply cuban_primes(1000),
+ [7, 19, 37, 61, 127, 271, 331, 397, 547, 631, 919],
+ 'Example';