diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2023-11-28 11:11:30 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-28 11:11:30 +0000 |
| commit | 3351df5a9c4275dffc2013f88c20ea34972e1099 (patch) | |
| tree | a2e6216c933788e013ea5b875a2524a8c8132d71 | |
| parent | d13e14c8f86e076f4c55b09a954ccb9d3ac83304 (diff) | |
| parent | b25d7be5fb1d090cea6b41c889120de935c4b5e0 (diff) | |
| download | perlweeklychallenge-club-3351df5a9c4275dffc2013f88c20ea34972e1099.tar.gz perlweeklychallenge-club-3351df5a9c4275dffc2013f88c20ea34972e1099.tar.bz2 perlweeklychallenge-club-3351df5a9c4275dffc2013f88c20ea34972e1099.zip | |
Merge pull request #9148 from massa/massa/challenge245
This week's oneliners
| -rw-r--r-- | challenge-245/massa/raku/ch-1.raku | 58 | ||||
| -rw-r--r-- | challenge-245/massa/raku/ch-2.raku | 67 |
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!) + + |
