diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-07-22 00:18:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-22 00:18:04 +0100 |
| commit | c9aab7a2b619c471f3f6b65ae548e9067000bd8e (patch) | |
| tree | a9d9e358101f3842013c7dc13ee3dfea25e73d16 | |
| parent | d078752e52301993b10dbb5fff0da493897ce9af (diff) | |
| parent | 8399ab58a2d54bea0054dd0d0a2a208938ab3de8 (diff) | |
| download | perlweeklychallenge-club-c9aab7a2b619c471f3f6b65ae548e9067000bd8e.tar.gz perlweeklychallenge-club-c9aab7a2b619c471f3f6b65ae548e9067000bd8e.tar.bz2 perlweeklychallenge-club-c9aab7a2b619c471f3f6b65ae548e9067000bd8e.zip | |
Merge pull request #12379 from seaker/master
challenge 331, raku solutions
| -rwxr-xr-x | challenge-331/feng-chang/raku/ch-1.raku | 5 | ||||
| -rwxr-xr-x | challenge-331/feng-chang/raku/ch-2.raku | 12 | ||||
| -rwxr-xr-x | challenge-331/feng-chang/raku/test.raku | 25 |
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'; |
