aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2023-10-10 17:01:41 +0800
committer冯昶 <fengchang@novel-supertv.com>2023-10-10 17:01:41 +0800
commit39dda85aa681328178935c4bc0c0fe87c9e63f60 (patch)
tree9da1f46f2f1a08d49397ecdc66f5e04b877cf634
parent24c95169da60a6a449046084057f7d65cb2e237e (diff)
downloadperlweeklychallenge-club-39dda85aa681328178935c4bc0c0fe87c9e63f60.tar.gz
perlweeklychallenge-club-39dda85aa681328178935c4bc0c0fe87c9e63f60.tar.bz2
perlweeklychallenge-club-39dda85aa681328178935c4bc0c0fe87c9e63f60.zip
challenge 238, raku solutions
-rwxr-xr-xchallenge-238/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-238/feng-chang/raku/ch-2.raku17
-rwxr-xr-xchallenge-238/feng-chang/raku/test.raku25
3 files changed, 47 insertions, 0 deletions
diff --git a/challenge-238/feng-chang/raku/ch-1.raku b/challenge-238/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..41c368c763
--- /dev/null
+++ b/challenge-238/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+put [\+] @ints;
diff --git a/challenge-238/feng-chang/raku/ch-2.raku b/challenge-238/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..06ff6b6961
--- /dev/null
+++ b/challenge-238/feng-chang/raku/ch-2.raku
@@ -0,0 +1,17 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+put @ints.sort({ steps($_), $_ });
+
+sub steps(UInt:D $n --> UInt:D) {
+ my $steps = 0;
+ my $m = $n;
+
+ while $m.chars > 1 {
+ $m = [*] $m.comb;
+ ++$steps;
+ }
+
+ $steps
+}
diff --git a/challenge-238/feng-chang/raku/test.raku b/challenge-238/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..8b3c0c2762
--- /dev/null
+++ b/challenge-238/feng-chang/raku/test.raku
@@ -0,0 +1,25 @@
+#!/bin/env raku
+
+# The Weekly Challenge 238
+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, Running Sum
+pwc-test './ch-1.raku', |<1 2 3 4 5>, '1 3 6 10 15', 'Running Sum: (1, 2, 3, 4, 5) => (1, 3, 6, 10, 15)';
+pwc-test './ch-1.raku', |<1 1 1 1 1>, '1 2 3 4 5', 'Running Sum: (1, 1, 1, 1, 1) => (1, 2, 3, 4, 5)';
+pwc-test './ch-1.raku', |<0 -1 1 2>, '0 -1 0 2', 'Running Sum: (0, -1, 1, 2) => (0, -1, 0, 2)';
+
+# Task 2, Persistence Sort
+pwc-test './ch-2.raku', |<15 99 1 34>, '1 15 34 99', 'Persistence Sort: (15, 99, 1, 34) => (1, 15, 34, 99)';
+pwc-test './ch-2.raku', |<50 25 33 22>, '22 33 50 25', 'Persistence Sort: (50, 25, 33, 22) => (22, 33, 50, 25)';
+
+done-testing;