aboutsummaryrefslogtreecommitdiff
path: root/challenge-139
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2021-11-18 09:26:09 +0000
committerdrbaggy <js5@sanger.ac.uk>2021-11-18 09:26:09 +0000
commitb3debed61af3381c91e9fff97167f14bbb85d29d (patch)
tree03af90bc0329e23d21292b452743d27f0a11ac2f /challenge-139
parent355ffd9e1f06f431fc5dbd9b374a97bf5537029f (diff)
parent60f80adda58560bfabecf16e825058b2ac227c42 (diff)
downloadperlweeklychallenge-club-b3debed61af3381c91e9fff97167f14bbb85d29d.tar.gz
perlweeklychallenge-club-b3debed61af3381c91e9fff97167f14bbb85d29d.tar.bz2
perlweeklychallenge-club-b3debed61af3381c91e9fff97167f14bbb85d29d.zip
Merge branch 'master' of github.com:drbaggy/perlweeklychallenge-club
git pull# Please enter a commit message to explain why this merge is necessary,
Diffstat (limited to 'challenge-139')
-rw-r--r--challenge-139/james-smith/README.md10
1 files changed, 5 insertions, 5 deletions
diff --git a/challenge-139/james-smith/README.md b/challenge-139/james-smith/README.md
index b1e418d85e..12cbf5c99d 100644
--- a/challenge-139/james-smith/README.md
+++ b/challenge-139/james-smith/README.md
@@ -26,7 +26,7 @@ This challenge is relatively easy - to see if the list of numbers if monotonical
* Otherwise we set previous number `$p` to the current number and continue
* If we get to the end of the list then the list is sorted and we return `1`.
-```
+```perl
sub in_order {
my $p = shift;
($p>$_) ? (return 0) : ($p=$_) for @_;
@@ -38,7 +38,7 @@ sub in_order {
* We can rewrite the `if( $x ) { y } else { z }` and `($x) ? (y) : (z)`. Why is this useful - well we can then use the brace less postfix `for` for the loop rather than having to use braces. This means the loop becomes 1 line, rather than the longer 7 line version using K&R braces. If you don't cuddle your braces it is even longer!
-```
+```perl
for (@_) {
if( $p>$_ ) {
return 0;
@@ -50,7 +50,7 @@ sub in_order {
Admittedly there is an intermediate version... That uses the exit early approach..
-```
+```perl
for (@_) {
return 0 if $p>$_;
$p = $_;
@@ -74,7 +74,7 @@ Now we don't require the actual part of the number repeats which makes the funct
This gives us the function below to get the length of the recurring sequence.
-```
+```perl
sub rec_len {
my( $D, $N, $s ) = ( shift, 1, '' );
( $s, $N ) = ( $s.int($N/$D), ($N%$D).0 ) for 0 .. 2*$D;
@@ -89,7 +89,7 @@ So now we have this function we can look at computing the long primes. We know t
Therefore we loop through all the odd numbers checking to see if the number is a prime, if it is we then check for the property that the recurring sequence has `$p-1` digits.
-```
+```perl
my( $N, @primes, @long_primes ) = ( $ARGV[0]||5 );
O: for( my $p=3; @long_primes<$N; $p+=2 ) {