aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Anderson <mark@andemark.io>2024-07-08 06:54:58 +0000
committerMark Anderson <mark@andemark.io>2024-07-08 06:54:58 +0000
commit3dbb3e9f107976d5404043a8f63f4cd4c1782b21 (patch)
treefa38b126ec9e158cfc3659d18358bec00fb109b2
parent996112d2e3daa2be2425e08aec3ce172f71b841b (diff)
downloadperlweeklychallenge-club-3dbb3e9f107976d5404043a8f63f4cd4c1782b21.tar.gz
perlweeklychallenge-club-3dbb3e9f107976d5404043a8f63f4cd4c1782b21.tar.bz2
perlweeklychallenge-club-3dbb3e9f107976d5404043a8f63f4cd4c1782b21.zip
Challenge 277 Solutions (Raku)
-rw-r--r--challenge-277/mark-anderson/raku/ch-1.raku16
-rw-r--r--challenge-277/mark-anderson/raku/ch-2.raku13
2 files changed, 29 insertions, 0 deletions
diff --git a/challenge-277/mark-anderson/raku/ch-1.raku b/challenge-277/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..108d7c9b59
--- /dev/null
+++ b/challenge-277/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,16 @@
+#!/usr/bin/env raku
+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;
+
+sub count-common(@words1, @words2)
+{
+ (@words1.grep(@words1.one) (&) @words2.grep(@words2.one)).elems
+}
diff --git a/challenge-277/mark-anderson/raku/ch-2.raku b/challenge-277/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..480fb6932c
--- /dev/null
+++ b/challenge-277/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,13 @@
+#!/usr/bin/env raku
+use Test;
+
+is strong-pair([1,2,3,4,5]), 4;
+is strong-pair([5,7,1,7]), 1;
+
+sub strong-pair(@ints)
+{
+ @ints.unique
+ .combinations(2)
+ .grep({ 0 < abs(.[0] - .[1]) < min(.[0], .[1]) })
+ .elems
+}