aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2023-03-20 22:53:50 +0000
committerGitHub <noreply@github.com>2023-03-20 22:53:50 +0000
commita211182f33e82c555fbbf729e124fd667f3d1b44 (patch)
treec91426c7de28d57eb09d31d32a3bfc56bb18c594
parentc9eb1d7d7e40fc1180e8afb0b814a44a8c727bc4 (diff)
downloadperlweeklychallenge-club-a211182f33e82c555fbbf729e124fd667f3d1b44.tar.gz
perlweeklychallenge-club-a211182f33e82c555fbbf729e124fd667f3d1b44.tar.bz2
perlweeklychallenge-club-a211182f33e82c555fbbf729e124fd667f3d1b44.zip
Update README.md
-rw-r--r--challenge-209/james-smith/README.md17
1 files changed, 17 insertions, 0 deletions
diff --git a/challenge-209/james-smith/README.md b/challenge-209/james-smith/README.md
index b190031e1c..908f8c30b2 100644
--- a/challenge-209/james-smith/README.md
+++ b/challenge-209/james-smith/README.md
@@ -30,6 +30,23 @@ sub special_bit_chars {
scalar @_
}
```
+## Solution 2
+
+As well as tracking from the front we can track from the back.
+
+First we need to note:
+
+ * Last character must be a `0`
+ * If there is string ending in a `0` then we can ignore anything up to this, as `0` is always at the right hand character in a string;
+ * Additionally if the last two characters are 0 then we know that the answer is true.
+ * So breaking this down we need to work out whether the value is true or false if the list ends: `.....,1,0`. If the string consists of series of `n` pairs of `1`s then this converts to "...CCA" and so the last character is `A` so we return 0; If it is an odd number of 1s we have the string "...CCB" so the return value is false.
+
+```perl
+sub special_bit_chars_reverse {
+ my$f,pop?return-1:pop||return 1;
+ $f=!$f,pop||last while@_;
+ ~~$f
+}
# Task 2: Merge Account