diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-03-18 05:09:02 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-18 05:09:02 +0000 |
| commit | e41e5c272308df6b03c7e2e8dac8dfe6641e6452 (patch) | |
| tree | d27df9e3c0ed41f2b373a29d4895db5cecdbe3e0 | |
| parent | 9823c1e77ae7fb7d9bfa4649c4bcf703cc806579 (diff) | |
| parent | 8267e2a0a293fcdba3446fed6a622f63e8b06580 (diff) | |
| download | perlweeklychallenge-club-e41e5c272308df6b03c7e2e8dac8dfe6641e6452.tar.gz perlweeklychallenge-club-e41e5c272308df6b03c7e2e8dac8dfe6641e6452.tar.bz2 perlweeklychallenge-club-e41e5c272308df6b03c7e2e8dac8dfe6641e6452.zip | |
Merge pull request #9763 from wambash/challenge-week-260
solutions week 260
| -rw-r--r-- | challenge-260/wambash/raku/ch-1.raku | 21 | ||||
| -rw-r--r-- | challenge-260/wambash/raku/ch-2.raku | 34 |
2 files changed, 55 insertions, 0 deletions
diff --git a/challenge-260/wambash/raku/ch-1.raku b/challenge-260/wambash/raku/ch-1.raku new file mode 100644 index 0000000000..f9b9be9347 --- /dev/null +++ b/challenge-260/wambash/raku/ch-1.raku @@ -0,0 +1,21 @@ +#!/usr/bin/env raku + +sub unique-occurences (+ints) { + ints + andthen .Bag + andthen .values + andthen .repeated + andthen .not +} + +multi MAIN (Bool :test($)!) { + use Test; + is unique-occurences(1,2,2,1,1,3),True; + is unique-occurences(1,2,3),False; + is unique-occurences(-2,0,1,-2,1,1,0,1,-2,9),True; + done-testing; +} + +multi MAIN (+ints) { + say +unique-occurences ints +} diff --git a/challenge-260/wambash/raku/ch-2.raku b/challenge-260/wambash/raku/ch-2.raku new file mode 100644 index 0000000000..ebc44b3d1c --- /dev/null +++ b/challenge-260/wambash/raku/ch-2.raku @@ -0,0 +1,34 @@ +#!/usr/bin/env raku + + +sub dr-iter ($word, %letters){ + %letters ∖ $word.comb + andthen .keys + andthen .sort + andthen $word X~ $_ +} + +sub dictionary-rank ($word) { + my %letters := $word.comb.Bag ; + + q{}, { .map: { |dr-iter $_, %letters } } ... * + andthen .skip: $word.chars + andthen .head + andthen .first: $word, :k + andthen $_ + 1 +} + +multi MAIN (Bool :test($)!) { + use Test; + is dr-iter('c', bag <a a b> ), <ca cb>; + is dictionary-rank('CAT'),3; + is dictionary-rank('GOOGLE'), 88; + is dictionary-rank('SECRET'), 255; + is dictionary-rank('Mississippi'), 1137; + is dictionary-rank('MISSISSIPPI'), 13737; + done-testing; +} + +multi MAIN ($word) { + say dictionary-rank $word +} |
