aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2021-11-16 14:44:49 +0000
committerdrbaggy <js5@sanger.ac.uk>2021-11-16 14:44:49 +0000
commit45c65f5a0c94cb0d4f8b4e4e423ba7a417ef871b (patch)
tree2208ddd8007d629b910809ea9c3283cdd11518f0
parentc1e8f201866be0b88efcf7c53801db80cc844255 (diff)
downloadperlweeklychallenge-club-45c65f5a0c94cb0d4f8b4e4e423ba7a417ef871b.tar.gz
perlweeklychallenge-club-45c65f5a0c94cb0d4f8b4e4e423ba7a417ef871b.tar.bz2
perlweeklychallenge-club-45c65f5a0c94cb0d4f8b4e4e423ba7a417ef871b.zip
save a line!
-rw-r--r--challenge-139/james-smith/perl/ch-2.pl5
1 files changed, 2 insertions, 3 deletions
diff --git a/challenge-139/james-smith/perl/ch-2.pl b/challenge-139/james-smith/perl/ch-2.pl
index 8eea2a8664..663dab1aa6 100644
--- a/challenge-139/james-smith/perl/ch-2.pl
+++ b/challenge-139/james-smith/perl/ch-2.pl
@@ -7,7 +7,7 @@ use feature qw(say);
my( $N, @primes, @long_primes ) = ( $ARGV[0]||5, 2 );
O: for( my $p=3; @long_primes<$N; $p+=2 ) {
- ($p % $_) || (next O) for @primes; ## next if !prime
+ ($p % $_) || (next O) for @primes;
push @long_primes, $p if $p - rec_len($p) == 1;
push @primes, $p;
}
@@ -17,6 +17,5 @@ say $_ for @long_primes;
sub rec_len {
my( $D, $N, $s ) = ( shift, 1, '' );
($s,$N) = ( $s.int($N/$D), ($N%$D).0 ) for 0 .. 2*$D;
- $s =~ m{(\d+?)\1+$};
- length $1;
+ $s =~ /(\d+?)\1+$/ ? length $1 : 0;
}