aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-278/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-278/feng-chang/raku/ch-2.raku8
-rwxr-xr-xchallenge-278/feng-chang/raku/test.raku29
3 files changed, 42 insertions, 0 deletions
diff --git a/challenge-278/feng-chang/raku/ch-1.raku b/challenge-278/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..e7d2471600
--- /dev/null
+++ b/challenge-278/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@words);
+
+put @words.map({ ~.[1] => ~.[0] with .match(/(\D+)(\d+)/) }).Hash.sort(+*.key)ยป.value.join(' ');
diff --git a/challenge-278/feng-chang/raku/ch-2.raku b/challenge-278/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..fe02f16925
--- /dev/null
+++ b/challenge-278/feng-chang/raku/ch-2.raku
@@ -0,0 +1,8 @@
+#!/bin/env raku
+
+unit sub MAIN(Str:D $word is copy, Str:D \c where c.chars == 1);
+
+with $word.index(c) -> \idx {
+ $_ = .substr(0, idx+1).comb.sort.join ~ .substr(idx+1) with $word;
+}
+put $word;
diff --git a/challenge-278/feng-chang/raku/test.raku b/challenge-278/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..65fc641102
--- /dev/null
+++ b/challenge-278/feng-chang/raku/test.raku
@@ -0,0 +1,29 @@
+#!/bin/env raku
+
+# The Weekly Challenge 278
+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 String
+pwc-test './ch-1.raku', <and2 Raku3 cousins5 Perl1 are4>, 'Perl and Raku are cousins',
+ 'Sort String: "and2 Raku3 cousins5 Perl1 are4" => "Perl and Raku are cousins"';
+pwc-test './ch-1.raku', <guest6 Python1 most4 the3 popular5 is2 language7>, 'Python is the most popular guest language',
+ 'Sort String: "guest6 Python1 most4 the3 popular5 is2 language7" => "Python is the most popular guest language"';
+pwc-test './ch-1.raku', <Challenge3 The1 Weekly2>, 'The Weekly Challenge',
+ 'Sort String: "Challenge3 The1 Weekly2" => "The Weekly Challenge"';
+pwc-test './ch-1.raku', <j10 i9 h8 g7 f6 e5 d4 c3 b2 a1>, 'a b c d e f g h i j',
+ 'Sort String: "j10 i9 h8 g7 f6 e5 d4 c3 b2 a1" => "a b c d e f g h i j"';
+
+# Task 2, Reverse Word
+pwc-test './ch-2.raku', 'challenge', 'e', 'acehllnge', 'Reverse Word: $str="challenge", $char="e" => "acehllnge"';
+pwc-test './ch-2.raku', 'programming', 'a', 'agoprrmming', 'Reverse Word: $str="programming", $char="a" => "agoprrmming"';
+pwc-test './ch-2.raku', 'champion', 'b', 'champion', 'Reverse Word: $str="champion", $char="b" => "champion"';