aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2022-02-12 23:54:23 +0000
committerGitHub <noreply@github.com>2022-02-12 23:54:23 +0000
commitd5da61dc5c795752917d1d74d57be5613fb0f63b (patch)
tree866c2a4fc5dc93cd96b7b7b006cf8ab7c0ed1ff8
parente0d91e53765a48f292162d7d01f3397fe29a06d3 (diff)
downloadperlweeklychallenge-club-d5da61dc5c795752917d1d74d57be5613fb0f63b.tar.gz
perlweeklychallenge-club-d5da61dc5c795752917d1d74d57be5613fb0f63b.tar.bz2
perlweeklychallenge-club-d5da61dc5c795752917d1d74d57be5613fb0f63b.zip
Update README.md
-rw-r--r--challenge-151/james-smith/README.md16
1 files changed, 16 insertions, 0 deletions
diff --git a/challenge-151/james-smith/README.md b/challenge-151/james-smith/README.md
index b6806a1ee6..01e099b2ca 100644
--- a/challenge-151/james-smith/README.md
+++ b/challenge-151/james-smith/README.md
@@ -62,6 +62,8 @@ We will only ever skip one or two houses at each "jump", we will never skip more
`--->------>------>------>------>------>---'
```
+### First attempt ...
+
Here we construct and array of the best total we could achieve if we stopped at the 1st, 2nd, 3rd houses etc...
For the first two:
@@ -82,3 +84,17 @@ sub rob {
```
*We could have written the second line with `1` & `0` not `-1` and `-2` but there is something about the symmetry of the two lines which is poetic*
+
+### Second attempt ...
+
+As we only need the previous 2 houses, we can do away with the array and just work with the score of the two previous entries.
+
+```perl
+sub rob_no_array {
+ my$p=my$q=0;
+ ($p,$q)=($q,$q>$p+$_?$q:$p+$_)for@_;
+ $q;
+}
+```
+
+Speedwise this is about 10% faster...