aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
}