aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-01-23 01:08:54 +0000
committerGitHub <noreply@github.com>2023-01-23 01:08:54 +0000
commit3a387476866d4bbdd5b514e4a99c04f0145296e4 (patch)
treef069953706d41a3114315b1106b59dccf61ce9cc
parent65f2b8f0df28d229f16ea65bfcc9fe9975edb55a (diff)
parent48aff39c47ee94ac1c163f41fc55643627d97dec (diff)
downloadperlweeklychallenge-club-3a387476866d4bbdd5b514e4a99c04f0145296e4.tar.gz
perlweeklychallenge-club-3a387476866d4bbdd5b514e4a99c04f0145296e4.tar.bz2
perlweeklychallenge-club-3a387476866d4bbdd5b514e4a99c04f0145296e4.zip
Merge pull request #7453 from 2colours/branch-for-challenge-200
Partial solution of week 200 by 2colours
-rwxr-xr-xchallenge-200/2colours/raku/ch-1.raku40
1 files changed, 40 insertions, 0 deletions
diff --git a/challenge-200/2colours/raku/ch-1.raku b/challenge-200/2colours/raku/ch-1.raku
new file mode 100755
index 0000000000..2d65746b9c
--- /dev/null
+++ b/challenge-200/2colours/raku/ch-1.raku
@@ -0,0 +1,40 @@
+#!/usr/bin/env raku
+
+my token unsigned-integer { 0 | <[1..9]><[0..9]>* };
+my token integer { '-'? <unsigned-integer> };
+subset IntList of Str where /^ '(' <integer>* % ',' ')' $/;
+
+proto infix:<l?,>($l, $r) is assoc<left> is equiv(&infix:<,>) {*}
+multi infix:<l?,>(Pair $l, Pair $r) {
+ samewith([[$l],], $r);
+}
+multi infix:<l?,>(Array $l, Pair $r) {
+ if $l.tail[0].value == $r.value {
+ $l.tail.push: $r;
+ }
+ else {
+ $l.push: [$r]
+ }
+ $l
+}
+
+
+sub MAIN(Str $array) {
+ die 'Please supply a valid list of integers.' unless $array.subst(/\s/, '', :g) ~~ IntList;
+ my Int() @array = $<integer>;
+ my @arithmetic-parts <==
+ @array.skip Z- @array andthen
+ [l?,] .pairs andthen
+ $_>>.key>>.minmax;
+ my @good-slices = gather for @arithmetic-parts {
+ given .min .. .max+1 { #convert from difference indexes to original indexes
+ for .min .. .max - 2 -> $start {
+ for $start + 2 .. .max -> $end {
+ take @array[$start .. $end];
+ }
+ }
+ }
+ }
+ @good-slices.map(*[].raku).join(', ').say;
+}
+