aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2023-11-20 16:42:55 +0800
committer冯昶 <fengchang@novel-supertv.com>2023-11-20 16:42:55 +0800
commit88ab292bff28e87e712243e6e8c028e0eb1243bd (patch)
tree93648047f8cb7f3c64b41bda7ea31927f854090a
parent72dc5412e640e26601ffdebc4f0247db4c4bc7fe (diff)
downloadperlweeklychallenge-club-88ab292bff28e87e712243e6e8c028e0eb1243bd.tar.gz
perlweeklychallenge-club-88ab292bff28e87e712243e6e8c028e0eb1243bd.tar.bz2
perlweeklychallenge-club-88ab292bff28e87e712243e6e8c028e0eb1243bd.zip
challenge 244, raku solutions
-rwxr-xr-xchallenge-244/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-244/feng-chang/raku/ch-2.raku5
-rwxr-xr-xchallenge-244/feng-chang/raku/test.raku24
3 files changed, 34 insertions, 0 deletions
diff --git a/challenge-244/feng-chang/raku/ch-1.raku b/challenge-244/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..f40b300083
--- /dev/null
+++ b/challenge-244/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+put @ints.map({ +@ints.grep(* < $_) });
diff --git a/challenge-244/feng-chang/raku/ch-2.raku b/challenge-244/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..ff9676ae26
--- /dev/null
+++ b/challenge-244/feng-chang/raku/ch-2.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+put @ints.combinations(1..Inf).map({ .max² * .min }).sum;
diff --git a/challenge-244/feng-chang/raku/test.raku b/challenge-244/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..3426425b6b
--- /dev/null
+++ b/challenge-244/feng-chang/raku/test.raku
@@ -0,0 +1,24 @@
+#!/bin/env raku
+
+# The Weekly Challenge 244
+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, Count Smaller
+pwc-test './ch-1.raku', |<8 1 2 2 3>, '4 0 1 1 3', 'Count Smaller: @nums = (8, 1, 2, 2, 3) => (4, 0, 1, 1, 3)';
+pwc-test './ch-1.raku', |<6 5 4 8>, '2 1 0 3', 'Count Smaller: @nums = (6, 5, 4, 8) => (2, 1, 0, 3)';
+pwc-test './ch-1.raku', |<2 2 2>, '0 0 0', 'Count Smaller: @nums = (2, 2, 2) => (0, 0, 0)';
+
+# Task 2, Group Hero
+pwc-test './ch-2.raku', |<2 1 4>, 141, 'Group Hero: (2, 1, 4) => 141';
+
+done-testing;