aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-07-11 09:45:13 +0100
committerGitHub <noreply@github.com>2024-07-11 09:45:13 +0100
commit3bfb291f8c6105a572754e02b0d4797a15fe2bb7 (patch)
tree6c5f1591067efd763839f83ab86c318fd5c443c9
parentdbc33a9e617a335c0bc91255f795e84cd62ffa13 (diff)
parentb998fcf374ff55b6eb19eea6e79a55866167d7f1 (diff)
downloadperlweeklychallenge-club-3bfb291f8c6105a572754e02b0d4797a15fe2bb7.tar.gz
perlweeklychallenge-club-3bfb291f8c6105a572754e02b0d4797a15fe2bb7.tar.bz2
perlweeklychallenge-club-3bfb291f8c6105a572754e02b0d4797a15fe2bb7.zip
Merge pull request #10410 from wambash/challenge-week-277
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
+}