aboutsummaryrefslogtreecommitdiff
path: root/challenge-158
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-04-03 18:28:02 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-04-03 18:28:02 +0100
commitca99c2fbb53988ba726be364def605c27328dadc (patch)
tree817a69c40ba6322976a4d7cf92dfad3eb879428d /challenge-158
parentd629ae2179384a9f42f2697788b438dab526ea19 (diff)
downloadperlweeklychallenge-club-ca99c2fbb53988ba726be364def605c27328dadc.tar.gz
perlweeklychallenge-club-ca99c2fbb53988ba726be364def605c27328dadc.tar.bz2
perlweeklychallenge-club-ca99c2fbb53988ba726be364def605c27328dadc.zip
- Added solutions by Pete Houston.
Diffstat (limited to 'challenge-158')
-rwxr-xr-xchallenge-158/pete-houston/perl/ch-1.pl24
-rwxr-xr-xchallenge-158/pete-houston/perl/ch-2.pl40
2 files changed, 64 insertions, 0 deletions
diff --git a/challenge-158/pete-houston/perl/ch-1.pl b/challenge-158/pete-houston/perl/ch-1.pl
new file mode 100755
index 0000000000..051187433f
--- /dev/null
+++ b/challenge-158/pete-houston/perl/ch-1.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+#===============================================================================
+#
+# FILE: 15801.pl
+#
+# USAGE: ./15801.pl
+#
+# DESCRIPTION: Output all Additive Primes <= 100
+#
+# REQUIREMENTS: List::Util, Math::Prime::Util
+# AUTHOR: Pete Houston (pete), cpan@openstrike.co.uk
+# ORGANIZATION: Openstrike
+# VERSION: 1.0
+# CREATED: 28/03/22
+#===============================================================================
+
+use strict;
+use warnings;
+use feature 'say';
+
+use List::Util qw/sum/;
+use Math::Prime::Util qw/is_prime primes/;
+
+say join ', ', grep { is_prime (sum split //) } @{primes (100)};
diff --git a/challenge-158/pete-houston/perl/ch-2.pl b/challenge-158/pete-houston/perl/ch-2.pl
new file mode 100755
index 0000000000..384b2dfccb
--- /dev/null
+++ b/challenge-158/pete-houston/perl/ch-2.pl
@@ -0,0 +1,40 @@
+#!/usr/bin/env perl
+#===============================================================================
+#
+# FILE: 15802.pl
+#
+# USAGE: ./15802.pl
+#
+# DESCRIPTION: Output the first series Cuban Primes <= 1000
+#
+# REQUIREMENTS: Math::Prime::Util, perl 5.10.0
+# AUTHOR: Pete Houston (pete), cpan@openstrike.co.uk
+# ORGANIZATION: Openstrike
+# VERSION: 1.0
+# CREATED: 28/03/22
+#===============================================================================
+
+use strict;
+use warnings;
+use feature 'state';
+
+use Math::Prime::Util 'is_prime';
+
+my @primes;
+my $cuban = next_cuban ();
+
+while ($cuban <= 1000) {
+ push @primes, $cuban if is_prime ($cuban);
+ $cuban = next_cuban ();
+}
+print "@primes\n";
+
+sub next_cuban {
+ state $cuberoot = 1;
+ state $cube = 1;
+
+ my $next = ++$cuberoot ** 3;
+ my $diff = $next - $cube;
+ $cube = $next;
+ return $diff;
+}