aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2021-06-21 07:40:55 +0100
committerdrbaggy <js5@sanger.ac.uk>2021-06-21 07:40:55 +0100
commit07f2d7eff881900aba2f53f844cf408750e3fe9c (patch)
treed4a8225ec662eab5cb2f60bc8f0f2521c59c9b27
parent257856af4578d1c050a2195e979e958f639b1056 (diff)
parentf4b0bbf549b27ea847de3961df44349879f4d265 (diff)
downloadperlweeklychallenge-club-07f2d7eff881900aba2f53f844cf408750e3fe9c.tar.gz
perlweeklychallenge-club-07f2d7eff881900aba2f53f844cf408750e3fe9c.tar.bz2
perlweeklychallenge-club-07f2d7eff881900aba2f53f844cf408750e3fe9c.zip
Merge branch 'master' of github.com:drbaggy/perlweeklychallenge-club
-rw-r--r--challenge-116/james-smith/README.md19
1 files changed, 12 insertions, 7 deletions
diff --git a/challenge-116/james-smith/README.md b/challenge-116/james-smith/README.md
index 9900d1f1f9..dfd11efa51 100644
--- a/challenge-116/james-smith/README.md
+++ b/challenge-116/james-smith/README.md
@@ -23,18 +23,23 @@ of the sequence (`$start.=$_`)....
Within each loop we just stitch together the string by incrementing the number each time through the loop..
- * We use string (in)equalities/incremements so this will work with arbitrarily large numbers (see examples in script)
- * We reduce the maximum calculations by a factor of 2 by spliting just the first half of the string
- * As we are working with strings rather than numbers we check the lengths in the while condition (because we are using string comparison)
+ * We use string (in)equalities/incremements so this will work with arbitrarily large numbers (see examples in script) (#1)
+
+ * We reduce the maximum calculations by a factor of 2 by spliting just the first half of the string (#2)
+
+ * As we are working with strings rather than numbers we check the lengths in the while condition (because we are using string comparison) (#3)
+
+ * We also check that the number we have just added is equal to the next chunk of the string (#4)
```perl
sub splitnum {
my( $in, $start ) = ( shift, '' );
- for( split //, substr $in, 0, (my $len = length $in) >> 1) {
+ for( split //, substr $in, 0, (my $len = length $in) >> 1) { #[2]
my @range = ( my $str = my $end = $start .= $_ );
- ($str .= ++$end) && push @range, $end while ($len > length $str) &&
- $end eq substr $in,length($str)-length($end),length($end);
- return \@range if $string eq $in;
+ ( $str .= ++$end ) && push @range, $end #[1]
+ while ($len > length $str) && #[3]
+ $end eq substr $in, length($str) - length($end) , length($end); #[4]
+ return \@range if $string eq $in; #[1]
}
return [$in];
}