aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark <53903062+andemark@users.noreply.github.com>2023-12-03 16:34:36 +0000
committerMark <53903062+andemark@users.noreply.github.com>2023-12-03 16:34:36 +0000
commitca202265b90fda5f53c9480ae4f08b5f58f67498 (patch)
tree3af6f5754eba5a4781287c5db49c62b9016a750f
parent42f3795a1b6f04418786c0837278b58bc910511b (diff)
downloadperlweeklychallenge-club-ca202265b90fda5f53c9480ae4f08b5f58f67498.tar.gz
perlweeklychallenge-club-ca202265b90fda5f53c9480ae4f08b5f58f67498.tar.bz2
perlweeklychallenge-club-ca202265b90fda5f53c9480ae4f08b5f58f67498.zip
Challenge 245 Solutions (Raku)
-rw-r--r--challenge-245/mark-anderson/raku/ch-1.raku10
-rw-r--r--challenge-245/mark-anderson/raku/ch-2.raku68
2 files changed, 78 insertions, 0 deletions
diff --git a/challenge-245/mark-anderson/raku/ch-1.raku b/challenge-245/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..a36321d822
--- /dev/null
+++ b/challenge-245/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,10 @@
+#!/usr/bin/env raku
+use Test;
+
+is-deeply sort-lang(<perl c python>, [2,1,3]), <c perl python>;
+is-deeply sort-lang(<c++ haskell java>, [1,3,2]), <c++ java haskell>;
+
+sub sort-lang(@languages, @popularities)
+{
+ .[@popularities] given [Any, |@languages]
+}
diff --git a/challenge-245/mark-anderson/raku/ch-2.raku b/challenge-245/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..5bbf9c5699
--- /dev/null
+++ b/challenge-245/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,68 @@
+#!/usr/bin/env raku
+use Test;
+
+# With help from https://www.geeksforgeeks.org/find-largest-multiple-3-array-digits-set-2-time-o1-space/
+
+is largest-of-three(8,1,9), 981;
+is largest-of-three(8,6,7,1,0), 8760;
+is largest-of-three(1), Nil;
+
+sub largest-of-three(*@n)
+{
+ @n .= sort(-*);
+
+ given @n.sum mod 3
+ {
+ when 0
+ {
+ return [~] @n
+ }
+
+ when 1
+ {
+ my $i = @n.first(* % 3 == 1, :k:end);
+
+ with $i
+ {
+ @n.splice($i, 1);
+ return @n.head ?? [~] @n !! Nil
+ }
+
+ else
+ {
+ return Nil
+ }
+ }
+
+ when 2
+ {
+ my $i = @n.first(* % 3 == 2, :k:end);
+
+ with $i
+ {
+ @n.splice($i, 1);
+ return @n.head ?? [~] @n !! Nil
+ }
+
+ else
+ {
+ for (^2)
+ {
+ my $i = @n.first(* % 3 == 1, :k:end);
+
+ with $i
+ {
+ @n.splice($i, 1);
+ }
+
+ else
+ {
+ return Nil
+ }
+ }
+
+ return @n.head ?? [~] @n !! Nil
+ }
+ }
+ }
+}