diff options
| -rw-r--r-- | challenge-277/mark-anderson/raku/ch-1.raku | 16 | ||||
| -rw-r--r-- | challenge-277/mark-anderson/raku/ch-2.raku | 13 |
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 +} |
