aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Krňávek <Jan.Krnavek@gmail.com>2024-03-18 05:58:13 +0100
committerJan Krňávek <Jan.Krnavek@gmail.com>2024-03-18 05:58:13 +0100
commit8267e2a0a293fcdba3446fed6a622f63e8b06580 (patch)
tree2d3c40a5c119cbba210f16e19b476801d9e9428a
parent6e7dbc4bfbded8facae0e97c23e62df680d979e4 (diff)
downloadperlweeklychallenge-club-8267e2a0a293fcdba3446fed6a622f63e8b06580.tar.gz
perlweeklychallenge-club-8267e2a0a293fcdba3446fed6a622f63e8b06580.tar.bz2
perlweeklychallenge-club-8267e2a0a293fcdba3446fed6a622f63e8b06580.zip
solutions week 260
-rw-r--r--challenge-260/wambash/raku/ch-1.raku21
-rw-r--r--challenge-260/wambash/raku/ch-2.raku34
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
+}