aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-10-07 10:59:43 +0100
committerGitHub <noreply@github.com>2025-10-07 10:59:43 +0100
commitbc2bb7c27507f804308dcf69d4a386fae8465683 (patch)
tree483307abea9a86c8e4b62d63d79bff3292f69358
parent22b39e684a80293624ef1e66f56fa087a07325b3 (diff)
parent9571888f05355711dab0e42155c403dfb8ba4f03 (diff)
downloadperlweeklychallenge-club-bc2bb7c27507f804308dcf69d4a386fae8465683.tar.gz
perlweeklychallenge-club-bc2bb7c27507f804308dcf69d4a386fae8465683.tar.bz2
perlweeklychallenge-club-bc2bb7c27507f804308dcf69d4a386fae8465683.zip
Merge pull request #12808 from ash/ash-342
Task 2 of Week 342, Raku by @ash
-rw-r--r--challenge-342/ash/raku/ch-2.raku23
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-342/ash/raku/ch-2.raku b/challenge-342/ash/raku/ch-2.raku
new file mode 100644
index 0000000000..555ee7e822
--- /dev/null
+++ b/challenge-342/ash/raku/ch-2.raku
@@ -0,0 +1,23 @@
+# Task 2 of the Weekly Challenge 342
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-342/#TASK2
+
+say max-score('0011'); # 4
+say max-score('0000'); # 3
+say max-score('1111'); # 3
+say max-score('0101'); # 3
+say max-score('011101'); # 5
+
+sub max-score($s) {
+ my $score = 0;
+ for 1 .. $s.chars - 1 -> $i {
+ my $left = $s.substr(0, $i);
+ my $right = $s.substr($i, $s.chars);
+
+ my $score-left = $left.comb('0').elems;
+ my $score-right = $right.comb('1').elems;
+
+ $score = max($score, $score-left + $score-right);
+ }
+
+ return $score;
+}