diff options
| author | Jason Messer <jasoncmesser@gmail.com> | 2020-09-14 00:08:49 -0700 |
|---|---|---|
| committer | Jason Messer <jasoncmesser@gmail.com> | 2020-09-14 00:08:49 -0700 |
| commit | d72f17e4bcf65cd6f8593134158386b3842b1dae (patch) | |
| tree | 34dafd0a316fe8a93b8c3cc09982df0b17401111 | |
| parent | 644bf1ea0c8c41e9858cb1cc3e4504dba72fb373 (diff) | |
| download | perlweeklychallenge-club-d72f17e4bcf65cd6f8593134158386b3842b1dae.tar.gz perlweeklychallenge-club-d72f17e4bcf65cd6f8593134158386b3842b1dae.tar.bz2 perlweeklychallenge-club-d72f17e4bcf65cd6f8593134158386b3842b1dae.zip | |
Raku solutions for week 78 challenge
| -rw-r--r-- | challenge-078/jason-messer/raku/ch-1.p6 | 15 | ||||
| -rw-r--r-- | challenge-078/jason-messer/raku/ch-2.p6 | 16 |
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-078/jason-messer/raku/ch-1.p6 b/challenge-078/jason-messer/raku/ch-1.p6 new file mode 100644 index 0000000000..e125bdfbac --- /dev/null +++ b/challenge-078/jason-messer/raku/ch-1.p6 @@ -0,0 +1,15 @@ +use v6.d; + +my @A = (9, 10, 7, 5, 6, 1); +my @B = (3, 4, 5); + +sub get-leaders(@a where .all > 0) { + my @leaders = gather for ^@a -> $i { + take @a[$i] if @a[$i + 1..*].grep( {@a[$i] < $_} ).elems == 0; + } + if @leaders == Empty { return (0).List } + return @leaders; +} + +say get-leaders(@A); +say get-leaders(@B); diff --git a/challenge-078/jason-messer/raku/ch-2.p6 b/challenge-078/jason-messer/raku/ch-2.p6 new file mode 100644 index 0000000000..2f42405dab --- /dev/null +++ b/challenge-078/jason-messer/raku/ch-2.p6 @@ -0,0 +1,16 @@ +use v6.d; + +my @A1 = (10, 20, 30, 40, 50); +my @B1 = (3, 4); + +my @A2 = (7, 4, 2, 6, 3); +my @B2 = (1, 3, 4); + +sub rotate-array-by(:@array, :@indices) { + gather for @indices { + take @array.rotate: $_; + } +} + +.say for rotate-array-by :array(@A1), :indices(@B1); +.say for rotate-array-by :array(@A2), :indices(@B2); |
