aboutsummaryrefslogtreecommitdiff
path: root/challenge-169/james-smith/perl
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2022-06-16 10:00:10 +0100
committerdrbaggy <js5@sanger.ac.uk>2022-06-16 10:00:10 +0100
commitc1ebaf2f59df349c8e82cda7f43ce40a5a431525 (patch)
tree7a13b245f89bfbddfb47947a2f514e6c8407f99f /challenge-169/james-smith/perl
parentd71fa6f60a0797100b3e151ea7f93d8f0b428423 (diff)
downloadperlweeklychallenge-club-c1ebaf2f59df349c8e82cda7f43ce40a5a431525.tar.gz
perlweeklychallenge-club-c1ebaf2f59df349c8e82cda7f43ce40a5a431525.tar.bz2
perlweeklychallenge-club-c1ebaf2f59df349c8e82cda7f43ce40a5a431525.zip
updates to make code more compact
Diffstat (limited to 'challenge-169/james-smith/perl')
-rw-r--r--challenge-169/james-smith/perl/ch-1-npp.pl18
-rw-r--r--challenge-169/james-smith/perl/ch-2-npp.pl18
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-169/james-smith/perl/ch-1-npp.pl b/challenge-169/james-smith/perl/ch-1-npp.pl
new file mode 100644
index 0000000000..ce0b88c777
--- /dev/null
+++ b/challenge-169/james-smith/perl/ch-1-npp.pl
@@ -0,0 +1,18 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Math::Prime::Util qw(factor);
+use Time::HiRes qw(time);
+
+my $time = time;
+
+#-------------------------------------------------------------------------------
+for( my( $c, $n, @f ) = 100; $c; ) {
+ $c--, say $n if 2 == ( @f = factor ++$n ) && length $f[0] == length $f[1];
+}
+
+warn 'Time taken: ', time-$time, "\n";
+
diff --git a/challenge-169/james-smith/perl/ch-2-npp.pl b/challenge-169/james-smith/perl/ch-2-npp.pl
new file mode 100644
index 0000000000..a3d686dc25
--- /dev/null
+++ b/challenge-169/james-smith/perl/ch-2-npp.pl
@@ -0,0 +1,18 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Math::Prime::Util qw(factor_exp gcd);
+use Time::HiRes qw(time);
+
+my $time = time;
+
+#-------------------------------------------------------------------------------
+for( my( $c, $n ) = ( 100 ); $c; ) {
+ $c--, say $n if 1 == gcd map{ $_->[1] < 2 ? next : $_->[1] } factor_exp ++$n;
+}
+
+warn 'Time taken: ', time-$time, "\n";
+