aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2025-07-21 14:52:37 +0800
committer冯昶 <fengchang@novel-supertv.com>2025-07-21 14:52:37 +0800
commit8399ab58a2d54bea0054dd0d0a2a208938ab3de8 (patch)
tree1711e4edda8988f52f697e1eaa7b7e20ee68685f
parente0f7e800fc8f1b2cb50896852a0a3ed61980f510 (diff)
downloadperlweeklychallenge-club-8399ab58a2d54bea0054dd0d0a2a208938ab3de8.tar.gz
perlweeklychallenge-club-8399ab58a2d54bea0054dd0d0a2a208938ab3de8.tar.bz2
perlweeklychallenge-club-8399ab58a2d54bea0054dd0d0a2a208938ab3de8.zip
challenge 331, raku solutions
-rwxr-xr-xchallenge-331/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-331/feng-chang/raku/ch-2.raku12
-rwxr-xr-xchallenge-331/feng-chang/raku/test.raku25
3 files changed, 42 insertions, 0 deletions
diff --git a/challenge-331/feng-chang/raku/ch-1.raku b/challenge-331/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..35ae2571f6
--- /dev/null
+++ b/challenge-331/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(Str:D $s);
+
+put $s.words.tail.chars;
diff --git a/challenge-331/feng-chang/raku/ch-2.raku b/challenge-331/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..d8680082d4
--- /dev/null
+++ b/challenge-331/feng-chang/raku/ch-2.raku
@@ -0,0 +1,12 @@
+#!/bin/env raku
+
+unit sub MAIN(Str:D $source, Str:D $target);
+
+put so (^$source.chars).combinations(2).map({ $source.&xchg($_) }).any eq $target;
+
+my method xchg(Str:D $s : @swp --> Str:D) {
+ with $s.comb -> @s is copy {
+ @s[@swp] = @s[@swp.reverse];
+ @s.join
+ }
+}
diff --git a/challenge-331/feng-chang/raku/test.raku b/challenge-331/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..f149860ade
--- /dev/null
+++ b/challenge-331/feng-chang/raku/test.raku
@@ -0,0 +1,25 @@
+#!/bin/env raku
+
+# The Weekly Challenge 331
+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, Last Word
+pwc-test './ch-1.raku', 'The Weekly Challenge', 9, 'Last Word: "The Weekly Challenge" => 9';
+pwc-test './ch-1.raku', ' Hello World ', 5, 'Last Word: " Hello World " => 5';
+pwc-test './ch-1.raku', "Let's begin the fun", 3, 'Last Word: "Let\'s begin the fun" => 3';
+
+# Task 2, Buddy Strings
+pwc-test './ch-2.raku', <fuck fcuk>, 'True', 'Buddy Strings: fuck fcuk => true';
+pwc-test './ch-2.raku', <love love>, 'False', 'Buddy Strings: love love => false';
+pwc-test './ch-2.raku', <fodo food>, 'True', 'Buddy Strings: fodo food => true';
+pwc-test './ch-2.raku', <feed feed>, 'True', 'Buddy Strings: feed feed => true';