diff options
| author | Polgár Márton <polgar@astron.hu> | 2023-01-23 01:13:12 +0100 |
|---|---|---|
| committer | Polgár Márton <polgar@astron.hu> | 2023-01-23 01:13:12 +0100 |
| commit | 48aff39c47ee94ac1c163f41fc55643627d97dec (patch) | |
| tree | 046dfa8d50abe70db2e8b649d57be0593462f556 | |
| parent | 952f98a3d4e479992cd18e544ebb441a952f7159 (diff) | |
| download | perlweeklychallenge-club-48aff39c47ee94ac1c163f41fc55643627d97dec.tar.gz perlweeklychallenge-club-48aff39c47ee94ac1c163f41fc55643627d97dec.tar.bz2 perlweeklychallenge-club-48aff39c47ee94ac1c163f41fc55643627d97dec.zip | |
Partial solution of week 200 by 2colours
| -rwxr-xr-x | challenge-200/2colours/raku/ch-1.raku | 40 |
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; +} + |
