aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-11-01 20:47:28 +0000
committerGitHub <noreply@github.com>2022-11-01 20:47:28 +0000
commitc447357f7e386ca7abf72ea1e639083697bf5e83 (patch)
tree1c0ce85967dbca631df419893a10f5c0de360e05
parentfba7fbfb7234fac4b2363c68e1c331dd7e94acae (diff)
parent434e373cc362ba32871a98a546f742a51f630a3f (diff)
downloadperlweeklychallenge-club-c447357f7e386ca7abf72ea1e639083697bf5e83.tar.gz
perlweeklychallenge-club-c447357f7e386ca7abf72ea1e639083697bf5e83.tar.bz2
perlweeklychallenge-club-c447357f7e386ca7abf72ea1e639083697bf5e83.zip
Merge pull request #7017 from 2colours/branch-for-challenge-189
Current weeklies by 2colours
-rwxr-xr-xchallenge-189/2colours/raku/ch-1.raku18
-rwxr-xr-xchallenge-189/2colours/raku/ch-2.raku20
2 files changed, 38 insertions, 0 deletions
diff --git a/challenge-189/2colours/raku/ch-1.raku b/challenge-189/2colours/raku/ch-1.raku
new file mode 100755
index 0000000000..70dc386acd
--- /dev/null
+++ b/challenge-189/2colours/raku/ch-1.raku
@@ -0,0 +1,18 @@
+#!/usr/bin/env raku
+
+subset ArrayOfCharacters of Str where /^ 'qw/' (<[a..z]>) ** 0..* % \s+ '/' $/;
+subset Character of Str where /^ \' (<[a..z]>) \' $/;
+
+sub MAIN(
+ $array, #= qw// style @array as string
+ $in-target #= character enclosed in apostrophes
+) {
+ die 'Invalid @array argument.' unless $array ~~ ArrayOfCharacters;
+ my @array = ~<<$0;
+ die 'Invalid $target argument' unless $in-target ~~ Character;
+ my $target = ~$0;
+ @array
+ .grep: * after $target andthen
+ .so ?? .min !! $target andthen
+ .say;
+} \ No newline at end of file
diff --git a/challenge-189/2colours/raku/ch-2.raku b/challenge-189/2colours/raku/ch-2.raku
new file mode 100755
index 0000000000..4fec2896a3
--- /dev/null
+++ b/challenge-189/2colours/raku/ch-2.raku
@@ -0,0 +1,20 @@
+#!/usr/bin/env raku
+
+
+subset ArrayOfPosInt of Str where /^ '(' (<[1..9]><[0..9]>*) ** 0..* % [\s* ',' \s*] ')' $/;
+
+sub MAIN(
+ $array, #= (x, y, z) style positive integer @array as string
+) {
+ die 'Invalid @array argument.' unless $array ~~ ArrayOfPosInt;
+ my @array = +<<$0;
+ my %positions = @array.antipairs.classify(*.key, as => *.value);
+ my $array-degree = %positions.map(*.value.elems).max;
+ my @common-value-ranges <==
+ %positions
+ .grep: *.value == $array-degree andthen
+ .map: *.value.minmax;
+ my $slice-size = @common-value-ranges>>.elems.min;
+ my @solution-ranges = @common-value-ranges.grep(* == $slice-size);
+ @array[@solution-ranges>>.Slip].map(*.raku).join(' or ').say;
+} \ No newline at end of file