aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2022-12-05 08:20:41 +0000
committerGitHub <noreply@github.com>2022-12-05 08:20:41 +0000
commit9e183fb259a4f5cbd51796fe06a9b15b42195757 (patch)
treefd33aa016f306f5a2bb5be6abd75405845049cd6
parent85fc1bf94b266eb1de8533c76bb7a0ca5a2a1041 (diff)
downloadperlweeklychallenge-club-9e183fb259a4f5cbd51796fe06a9b15b42195757.tar.gz
perlweeklychallenge-club-9e183fb259a4f5cbd51796fe06a9b15b42195757.tar.bz2
perlweeklychallenge-club-9e183fb259a4f5cbd51796fe06a9b15b42195757.zip
Update README.md
-rw-r--r--challenge-194/james-smith/README.md14
1 files changed, 10 insertions, 4 deletions
diff --git a/challenge-194/james-smith/README.md b/challenge-194/james-smith/README.md
index 5480e2db42..579581f98f 100644
--- a/challenge-194/james-smith/README.md
+++ b/challenge-194/james-smith/README.md
@@ -58,15 +58,21 @@ sub digit_2400 {
## Solution
-Again we use and IIFE. This time taking the value of the sorted values from `%sc`. For the method to be true. The sorted values must be:
+Again we use and IIFE. This time taking the value of the sorted values from `%f` (being the frequencies of each letter).
+For the method to be true. The sorted values must be:
* `n`, `n`, `n`, ...., `n`, `n+1`
-So we just need to check the 1st with the (n-1)st and the (n-1)st with the last!
+In fact if we reverse the sort (switch `$a` and `$b` around in the comparison) we have:
+
+ * `n+1`, `n`, `n`, ...., `n`, `n`
+
+So check to see if the first is one more than the second and the second is the same
+as the last.
```perl
sub check {
- my %sc; $sc{$_} ++ for split //,$_[0];
- sub { @_>2 && $_[0]==$_[1]+1 && $_[-1]==$_[1] ? 1 : 0 }->(sort {$b<=>$a} values %sc);
+ my %f; $f{$_} ++ for split //, $_[0];
+ sub { @_>2 && $_[0]==$_[1]+1 && $_[-1]==$_[1] }->(sort {$b<=>$a} values %f) || 0;
}
```