aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Smith <baggy@baggy.me.uk>2021-06-19 22:25:26 +0100
committerGitHub <noreply@github.com>2021-06-19 22:25:26 +0100
commitf4b0bbf549b27ea847de3961df44349879f4d265 (patch)
treead5df2bc0f83f7f59d78b92cd245fe6faf395c07
parentbee7fd4cecc5a5809a2c6ed519437374b8167133 (diff)
downloadperlweeklychallenge-club-f4b0bbf549b27ea847de3961df44349879f4d265.tar.gz
perlweeklychallenge-club-f4b0bbf549b27ea847de3961df44349879f4d265.tar.bz2
perlweeklychallenge-club-f4b0bbf549b27ea847de3961df44349879f4d265.zip
Update README.md
-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];
}