From 9571888f05355711dab0e42155c403dfb8ba4f03 Mon Sep 17 00:00:00 2001 From: Andrew Shitov Date: Tue, 7 Oct 2025 10:48:45 +0200 Subject: Task 2 of Week 342, Raku by @ash --- challenge-342/ash/raku/ch-2.raku | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 challenge-342/ash/raku/ch-2.raku 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; +} -- cgit