aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHumberto Massa <humbertomassa@gmail.com>2023-11-27 09:31:22 -0300
committerHumberto Massa <humbertomassa@gmail.com>2023-11-27 09:31:22 -0300
commitb25d7be5fb1d090cea6b41c889120de935c4b5e0 (patch)
tree574a4e83b1175124c5758f2bad7f6ac503ad66f1
parenta91d49494a545d745c5c622afa3a9646bf1ac774 (diff)
downloadperlweeklychallenge-club-b25d7be5fb1d090cea6b41c889120de935c4b5e0.tar.gz
perlweeklychallenge-club-b25d7be5fb1d090cea6b41c889120de935c4b5e0.tar.bz2
perlweeklychallenge-club-b25d7be5fb1d090cea6b41c889120de935c4b5e0.zip
This week's oneliners
-rw-r--r--challenge-245/massa/raku/ch-1.raku58
-rw-r--r--challenge-245/massa/raku/ch-2.raku67
2 files changed, 125 insertions, 0 deletions
diff --git a/challenge-245/massa/raku/ch-1.raku b/challenge-245/massa/raku/ch-1.raku
new file mode 100644
index 0000000000..1290eda32a
--- /dev/null
+++ b/challenge-245/massa/raku/ch-1.raku
@@ -0,0 +1,58 @@
+#! /usr/bin/env raku
+
+# Perl Weekly Challenge
+# © 2023 Shimon Bollinger. All rights reserved.
+# Last modified: Mon 15 May 2023 09:17:32 PM EDT
+# Version 0.0.1
+
+=begin pod
+=TITLE
+=head2 Task 1: Sort Language
+
+=SUBTITLE
+=head2 Submitted by massa
+
+=CHALLENGE
+=head2
+
+You are given two array of languages and its popularity.
+
+Write a script to sort the language based on popularity.
+
+=head3 Example 1:
+
+ Input: @lang = ('perl', 'c', 'python')
+ @popularity = (2, 1, 3)
+ Output: ('c', 'perl', 'python')=head3 Example 2:
+
+=head3 Example 3:
+
+ Input: @lang = ('c++', 'haskell', 'java')
+ @popularity = (1, 3, 2)
+ Output: ('c++', 'java', 'haskell')
+
+=SOLUTION
+
+=end pod
+
+# always use the latest version of Raku
+use v6.*;
+
+sub SOLUTION(@ (@lang, @pop)) {
+ (@pop Z=> @lang).sort(*.keys)».value
+}
+
+multi MAIN (Bool :$test!) {
+ use Test;
+
+ my @tests =
+ %{ input => (<perl c python>, (2, 1, 3)),
+ output => <c perl python> },
+ %{ input => (<c++ haskell java>, (1, 3, 2)),
+ output => <c++ java haskell> },
+ ;
+
+ .<input>.&SOLUTION.deepmap({$_}).&is-deeply: .<output>, .<text> for @tests
+} # end of multi MAIN (Bool :$test!)
+
+
diff --git a/challenge-245/massa/raku/ch-2.raku b/challenge-245/massa/raku/ch-2.raku
new file mode 100644
index 0000000000..fef55ba845
--- /dev/null
+++ b/challenge-245/massa/raku/ch-2.raku
@@ -0,0 +1,67 @@
+#! /usr/bin/env raku
+
+# Perl Weekly Challenge
+# © 2023 Shimon Bollinger. All rights reserved.
+# Last modified: Mon 15 May 2023 09:17:32 PM EDT
+# Version 0.0.1
+
+=begin pod
+=TITLE
+=head2 Task 2: Largest of Three
+
+=SUBTITLE
+=head2 Submitted by massa
+
+=CHALLENGE
+=head2
+
+You are given an array of integers >= 0.
+
+Write a script to return the largest number formed by concatenating some of the
+given integers in any order which is also multiple of 3. Return -1 if none
+found.
+
+=head3 Example 1:
+
+ Input: @digits = (8, 1, 9)
+ Output: 981
+
+ 981 % 3 == 0
+
+=head3 Example 2:
+
+ Input: @digits = (8, 6, 7, 1, 0)
+ Output: 8760
+
+=head3 Example 3:
+
+ Input: @digits = (1)
+ Output: -1
+
+=SOLUTION
+
+=end pod
+
+# always use the latest version of Raku
+use v6.*;
+
+sub SOLUTION(@_) {
+ @_.combinations.skip(1).map(*.permutations».join».Int).flat.sort(-*).first(* %% 3) or -1
+}
+
+multi MAIN (Bool :$test!) {
+ use Test;
+
+ my @tests =
+ %{ input => (8, 1, 9),
+ output => (981,) },
+ %{ input => (8, 6, 7, 1, 0),
+ output => (8760,) },
+ %{ input => (1,),
+ output => (-1,) },
+ ;
+
+ .<input>.&SOLUTION.deepmap({$_}).&is-deeply: .<output>, .<text> for @tests
+} # end of multi MAIN (Bool :$test!)
+
+