aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Davies <kaiepi@outlook.com>2020-03-02 16:11:07 -0400
committerBen Davies <kaiepi@outlook.com>2020-03-02 16:11:07 -0400
commit0113ccdd8a676829064c2a5ffc65e83a30e6a80a (patch)
tree836a4db746f5b3da11a83447d79b069af4921597
parent9b64aedf7cae92ccca617184662e133d651c0dee (diff)
downloadperlweeklychallenge-club-0113ccdd8a676829064c2a5ffc65e83a30e6a80a.tar.gz
perlweeklychallenge-club-0113ccdd8a676829064c2a5ffc65e83a30e6a80a.tar.bz2
perlweeklychallenge-club-0113ccdd8a676829064c2a5ffc65e83a30e6a80a.zip
Add Ben Davies' Raku solutions for challenge 50
-rw-r--r--challenge-050/ben-davies/README.md1
-rw-r--r--challenge-050/ben-davies/raku/ch-1.raku16
-rw-r--r--challenge-050/ben-davies/raku/ch-2.raku10
3 files changed, 27 insertions, 0 deletions
diff --git a/challenge-050/ben-davies/README.md b/challenge-050/ben-davies/README.md
new file mode 100644
index 0000000000..77158344c9
--- /dev/null
+++ b/challenge-050/ben-davies/README.md
@@ -0,0 +1 @@
+Solution by Ben Davies
diff --git a/challenge-050/ben-davies/raku/ch-1.raku b/challenge-050/ben-davies/raku/ch-1.raku
new file mode 100644
index 0000000000..42c4045774
--- /dev/null
+++ b/challenge-050/ben-davies/raku/ch-1.raku
@@ -0,0 +1,16 @@
+use v6.d;
+unit sub MAIN() {
+ my constant @INTERVALS = ((2, 7), (3, 9), (10, 12), (15, 19), (18, 22));
+ # - Flatten @INTERVALS:
+ # => (2, 7, 3, 9, 10, 12, 15, 19, 18, 22)
+ # - Take the first number:
+ # => (2)
+ # - Take any pairs of numbers in between the first and last ones where the
+ # first is lesser than the second (those that aren't overlap):
+ # => (2, 9, 10, 12, 15)
+ # - Take the last number:
+ # => (2, 9, 10, 12, 15, 22)
+ # - Pair the numbers back together:
+ # => ((2, 9), (10, 12), (15, 22))
+ say (.[0], |.[0^..^*-1].grep(* < *).flat, .[*-1]).rotor(2) given @INTERVALS.flat;
+}
diff --git a/challenge-050/ben-davies/raku/ch-2.raku b/challenge-050/ben-davies/raku/ch-2.raku
new file mode 100644
index 0000000000..5ee23a2899
--- /dev/null
+++ b/challenge-050/ben-davies/raku/ch-2.raku
@@ -0,0 +1,10 @@
+use v6.d;
+unit sub MAIN() {
+ # Two or more Noble Integers can exist in a list if they're equal 😉:
+ # my Int:D @L = (2, 2, 6, 1, 3);
+ my Int:D @L = (2, 6, 1, 3);
+ # Grep for all integers in @L where the list of integers in @L greater than
+ # said integer is equal in length to said integer:
+ say '<== ', @L;
+ say '==> ', @L.grep({ @L.grep(* > $_) == $_ });
+}