aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Krňávek <Jan.Krnavek@gmail.com>2024-07-11 09:38:14 +0200
committerJan Krňávek <Jan.Krnavek@gmail.com>2024-07-11 09:38:14 +0200
commitb998fcf374ff55b6eb19eea6e79a55866167d7f1 (patch)
tree5694e3b9c7d36d934e0a2e1d444be32ba91df0dc
parent4c44b94c1956d9472262323e26a7a6a901420686 (diff)
downloadperlweeklychallenge-club-b998fcf374ff55b6eb19eea6e79a55866167d7f1.tar.gz
perlweeklychallenge-club-b998fcf374ff55b6eb19eea6e79a55866167d7f1.tar.bz2
perlweeklychallenge-club-b998fcf374ff55b6eb19eea6e79a55866167d7f1.zip
solutions week 277
-rw-r--r--challenge-277/wambash/raku/ch-1.raku21
-rw-r--r--challenge-277/wambash/raku/ch-2.raku20
2 files changed, 41 insertions, 0 deletions
diff --git a/challenge-277/wambash/raku/ch-1.raku b/challenge-277/wambash/raku/ch-1.raku
new file mode 100644
index 0000000000..1f2d8d8f32
--- /dev/null
+++ b/challenge-277/wambash/raku/ch-1.raku
@@ -0,0 +1,21 @@
+#!/usr/bin/env raku
+
+sub count-common (+words) {
+ words
+ andthen .map: *.Bag
+ andthen .map: *.nodemap: * ≤ 1
+ andthen [∩] $_
+ andthen .elems
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is count-common(<Perl is my friend>, <Perl and Raku are friend>), 2;
+ is count-common(<Perl and Python are very similar>, <Python is top in guest languages>), 1;
+ is count-common(<Perl is imperative Lisp is functional>, <Crystal is Similar to Ruby>), 0;
+ done-testing;
+}
+
+multi MAIN (+words) {
+ say count-common words».words
+}
diff --git a/challenge-277/wambash/raku/ch-2.raku b/challenge-277/wambash/raku/ch-2.raku
new file mode 100644
index 0000000000..ec6c09b2f2
--- /dev/null
+++ b/challenge-277/wambash/raku/ch-2.raku
@@ -0,0 +1,20 @@
+#!/usr/bin/env raku
+
+sub strong-pair (+ints) {
+ ints
+ andthen .unique
+ andthen .combinations: 2
+ andthen .grep: -> ($x, $y) { 0 < abs( $x - $y ) < ($x min $y) }\
+ andthen .elems
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is strong-pair(1..5), 4;
+ is strong-pair(5,7,1,7), 1;
+ done-testing;
+}
+
+multi MAIN (+ints) {
+ say strong-pair ints
+}