diff options
| -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 +} |
