aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2023-11-27 16:29:57 +0800
committer冯昶 <fengchang@novel-supertv.com>2023-11-27 16:29:57 +0800
commit6f78aae3efa4642ffa271896203a09afce53e407 (patch)
tree03c1f432153302dba0bcaf9459cf67aa9f86b031
parentb61fcc8e834807b55db5ff45ef7c268081b9e0d1 (diff)
downloadperlweeklychallenge-club-6f78aae3efa4642ffa271896203a09afce53e407.tar.gz
perlweeklychallenge-club-6f78aae3efa4642ffa271896203a09afce53e407.tar.bz2
perlweeklychallenge-club-6f78aae3efa4642ffa271896203a09afce53e407.zip
challenge 245, raku solutions
-rwxr-xr-xchallenge-245/feng-chang/raku/ch-1.raku6
-rwxr-xr-xchallenge-245/feng-chang/raku/ch-2.raku5
-rwxr-xr-xchallenge-245/feng-chang/raku/test.raku33
3 files changed, 44 insertions, 0 deletions
diff --git a/challenge-245/feng-chang/raku/ch-1.raku b/challenge-245/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..d12847286b
--- /dev/null
+++ b/challenge-245/feng-chang/raku/ch-1.raku
@@ -0,0 +1,6 @@
+#!/bin/env raku
+
+unit sub MAIN(Str:D $langs, Str:D $popular);
+
+my %langs = $langs.words Z=> +«$popular.words;
+put %langs.keys.sort({ %langs{$_} });
diff --git a/challenge-245/feng-chang/raku/ch-2.raku b/challenge-245/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..4cba0247de
--- /dev/null
+++ b/challenge-245/feng-chang/raku/ch-2.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints where @ints.all ≥ 0);
+
+put @ints.combinations.grep(*.join %% 3).map({ .permutations.map(*.join) }).flat.max || -1;
diff --git a/challenge-245/feng-chang/raku/test.raku b/challenge-245/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..a14c97b30c
--- /dev/null
+++ b/challenge-245/feng-chang/raku/test.raku
@@ -0,0 +1,33 @@
+#!/bin/env raku
+
+# The Weekly Challenge 245
+use Test;
+
+sub pwc-test(Str:D $script, Bool :$deeply? = False, *@input) {
+ my ($expect, $assertion) = @input.splice(*-2, 2);
+ my $p = run $script, |@input, :out;
+ if $deeply {
+ is-deeply $p.out.slurp(:close).chomp.words.Bag, $expect, $assertion;
+ } else {
+ is $p.out.slurp(:close).chomp, $expect, $assertion;
+ }
+}
+
+# Task 1, Sort Language
+pwc-test './ch-1.raku',
+ 'perl c python',
+ '2 1 3',
+ 'c perl python',
+ 'Sort Language: @lang = ("perl", "c", "python"), @popularity = (2, 1, 3) => ("c", "perl", "python")';
+pwc-test './ch-1.raku',
+ 'c++ haskell java',
+ '1 3 2',
+ 'c++ java haskell',
+ 'Sort Language: @lang = ("c++", "haskell", "java"), @popularity = (1, 3, 2) => ("c++", "java", "haskell")';
+
+# Task 2, Largest of Three
+pwc-test './ch-2.raku', |<8 1 9>, 981, 'Largest of Three: (8, 1, 9) => 981';
+pwc-test './ch-2.raku', |<8 6 7 1 0>, 8760, 'Largest of Three: (8, 6, 7, 1, 0) => 8760';
+pwc-test './ch-2.raku', 1, -1, 'Largest of Three: (1) => -1';
+
+done-testing;