diff options
| author | rir <rirans@comcast.net> | 2024-07-25 11:25:49 -0400 |
|---|---|---|
| committer | rir <rirans@comcast.net> | 2024-07-25 11:27:31 -0400 |
| commit | 880a90924f2f061b2bc515bde4ca1043be2c97db (patch) | |
| tree | a86968fc192f8e71d9d001ed257fe733eea67cdf | |
| parent | 3d6cbce024396f3950dad9b40151458e4134202d (diff) | |
| download | perlweeklychallenge-club-880a90924f2f061b2bc515bde4ca1043be2c97db.tar.gz perlweeklychallenge-club-880a90924f2f061b2bc515bde4ca1043be2c97db.tar.bz2 perlweeklychallenge-club-880a90924f2f061b2bc515bde4ca1043be2c97db.zip | |
279
| -rw-r--r-- | challenge-279/0rir/raku/ch-1.raku | 61 | ||||
| -rw-r--r-- | challenge-279/0rir/raku/ch-2.raku | 62 |
2 files changed, 123 insertions, 0 deletions
diff --git a/challenge-279/0rir/raku/ch-1.raku b/challenge-279/0rir/raku/ch-1.raku new file mode 100644 index 0000000000..87667b97cb --- /dev/null +++ b/challenge-279/0rir/raku/ch-1.raku @@ -0,0 +1,61 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ « » ∴ +use v6.d; +INIT $*RAT-OVERFLOW = FatRat; +use lib $?FILE.IO.cleanup.parent(2).add("lib"); +use Test; + +=begin comment +279 1: Sort Letters Submitted by: Mohammad Sajid Anwar + +Given two arrays, @letters and @weights, sort the given array +@letters based on the @weights. + +Example 1 +Input: @letters = ('R', 'E', 'P', 'L') + @weights = (3, 2, 1, 4) +Output: PERL +Example 2 +Input: @letters = ('A', 'U', 'R', 'K') + @weights = (2, 4, 1, 3) +Output: RAKU +Example 3 +Input: @letters = ('O', 'H', 'Y', 'N', 'P', 'T') + @weights = (5, 4, 2, 6, 1, 3) +Output: PYTHON +=end comment + +my @Test = + ('R', 'E', 'P', 'L'), (3, 2, 1, 4), 'PERL', + ('A', 'U', 'R', 'K'), (2, 4, 1, 3), 'RAKU', + ('O', 'H', 'Y', 'N', 'P', 'T'), (5, 4, 2, 6, 1, 3), 'PYTHON', +; +my @Die = + < a a a a>, ( 1, 2, 3, 5), + < x x x x>, ( 1, 2,3,), +; +plan @Test ÷ 3 + @Die ÷ 2; + +sub task( @value, @order -->Str) { + my $ret; + die q{Err: Index count doesn't match data.} + unless @order.sort ~~ (1 … @value.elems); + for ^@order -> \i { + $ret[ @order[i] - 1 ] = @value[i]; + } + @$ret.join; +} + +for @Test -> @value, @order, $exp { + is task(@value, @order), $exp, "$exp <- @value.raku() ~o~ @order.raku()"; +} +for @Die -> @value, @order { + dies-ok { task(@value, @order)}, "dies <- @value.raku() ~o~ @order.raku()"; +} +done-testing; + +my @letter = < P E R L >; +my @weight = (3, 2, 1, 4); +say "\nInput : @letters = @letter.raku()\n @weights = @weight.raku()" + ~ "\nOutput: ", task( @letter, @weight); + diff --git a/challenge-279/0rir/raku/ch-2.raku b/challenge-279/0rir/raku/ch-2.raku new file mode 100644 index 0000000000..591c5cbc9c --- /dev/null +++ b/challenge-279/0rir/raku/ch-2.raku @@ -0,0 +1,62 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ « » ∴ +use v6.d; +use Test; + +=begin comment +279 2: Split String Submitted by: Mohammad Sajid Anwar + +Given a string, $str, split the given string into two containing +exactly same number of vowels and return true if you can otherwise false. + +Example 1 +Input: $str = "perl" +Ouput: false +Example 2 +Input: $str = "book" +Ouput: true + +Two possible strings "bo" and "ok" containing exactly one vowel each. +Example 3 +Input: $str = "good morning" +Ouput: true + +Two possible strings "good " and "morning" containing two vowels each or "good m" and "orning" containing two vowels each.k +=end comment + +my @Test = + # in expect + Str, Bool, + '', False, + ' ', False, + ',1,1', False, + 'o', False, + 'oo', True, + 'o1o', True, + 'ooo', False, + 'o1oo', False, + "perl", False, + "book", True, + 'aeiouAEIOU', True, + "good morning", True, + "Good mOrning", True, + "Go123od m,Orn:ing", True, + ('aeiouAEIOU' x 10), True, + ('aeiouAEIOU' x 10) ~ 'a', False, +; +plan @Test ÷ 2; + +multi task( Str:U $in ) { Bool } +multi task( Str:D $in --> Bool) { + my \v-ct := +$in.comb.grep( /:i <[aeiou]> / ); + return True if v-ct %% 2 and v-ct > 1 ; + False; +} + +for @Test -> $in, $exp { + is task($in), $exp, ($exp // '(Bool)') ~ "<- " ~ ($in // '(Bool)').raku +} +done-testing; + +my $str = 'x'; +say "\nInput: \$str = $str\nOutput: ", task $str; |
