aboutsummaryrefslogtreecommitdiff
path: root/challenge-210
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2023-04-02 22:46:02 +0100
committerGitHub <noreply@github.com>2023-04-02 22:46:02 +0100
commit41f81e6fd5e4d367ada5a0c93f83d9d38d4b933a (patch)
tree7da04ed466c2ec03edb78fafbf20bd9fc528c6bb /challenge-210
parentc7949ad5e1c94291ac7f5534da8f234169b4da18 (diff)
downloadperlweeklychallenge-club-41f81e6fd5e4d367ada5a0c93f83d9d38d4b933a.tar.gz
perlweeklychallenge-club-41f81e6fd5e4d367ada5a0c93f83d9d38d4b933a.tar.bz2
perlweeklychallenge-club-41f81e6fd5e4d367ada5a0c93f83d9d38d4b933a.zip
Update ch-1.pl
Diffstat (limited to 'challenge-210')
-rw-r--r--challenge-210/james-smith/perl/ch-1.pl12
1 files changed, 11 insertions, 1 deletions
diff --git a/challenge-210/james-smith/perl/ch-1.pl b/challenge-210/james-smith/perl/ch-1.pl
index 12f42c9fc4..62bf1402eb 100644
--- a/challenge-210/james-smith/perl/ch-1.pl
+++ b/challenge-210/james-smith/perl/ch-1.pl
@@ -20,4 +20,14 @@ sub kill_and_win {
$max ## return value
}
-is( kill_and_win( @{$_->[0]} ), $_->[1] ) for @TESTS;
+sub kill_and_win_total {
+ my($m,%t,$x)=0;
+ $t{$_} += $_ for @_; ## Get freq in hash
+ ( ( $x = ( $t{$_-1} // 0 ) ## Compute value
+ + ( $t{$_ } // 0 ) ## for current
+ + ( $t{$_+1} // 0 ) ## integer
+ ) > $m ) && ($m = $x) for keys %t; ## if max reset max
+ $m ## return value
+}
+
+is( kill_and_win_total( @{$_->[0]} ), $_->[1] ) for @TESTS;