diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-07-02 23:24:34 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-02 23:24:34 +0100 |
| commit | 9f20b07426921e808eef1bd3c5836b604fd78ca4 (patch) | |
| tree | 076937e1a18296af5e69dca573c4f4f56f3ac1ac | |
| parent | ffaea6f617df7834dc80c44f657e6f14d77c4ab0 (diff) | |
| parent | 9cf417a0bff2d1408ad28b46147ecebaa81215e9 (diff) | |
| download | perlweeklychallenge-club-9f20b07426921e808eef1bd3c5836b604fd78ca4.tar.gz perlweeklychallenge-club-9f20b07426921e808eef1bd3c5836b604fd78ca4.tar.bz2 perlweeklychallenge-club-9f20b07426921e808eef1bd3c5836b604fd78ca4.zip | |
Merge pull request #12261 from seaker/master
challenge 328, raku solutions
| -rwxr-xr-x | challenge-328/feng-chang/raku/ch-1.raku | 5 | ||||
| -rwxr-xr-x | challenge-328/feng-chang/raku/ch-2.raku | 10 | ||||
| -rwxr-xr-x | challenge-328/feng-chang/raku/test.raku | 24 |
3 files changed, 39 insertions, 0 deletions
diff --git a/challenge-328/feng-chang/raku/ch-1.raku b/challenge-328/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..a945f0e0fc --- /dev/null +++ b/challenge-328/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +unit sub MAIN(Str:D $s where *.match: /^ <[?a..z]>+ $/); + +put $s.subst(/(.)'?'(.)/, { ~$0 ~ (<a b c> (-) (~$0, ~$1)).keys.sort[0] ~ $1 }, :g); diff --git a/challenge-328/feng-chang/raku/ch-2.raku b/challenge-328/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..2c8bed2d59 --- /dev/null +++ b/challenge-328/feng-chang/raku/ch-2.raku @@ -0,0 +1,10 @@ +#!/bin/env raku + +unit sub MAIN(Str:D $s is copy where *.match: /^ <[a..zA..Z]>+ $/); + +while $s.subst-mutate(/(.)(.) <?{ is-upper-lower(~$0, ~$1) }>/, '') { } +put $s; + +sub is-upper-lower(Str:D $c1, Str:D $c2 --> Bool:D) { + abs($c1.ord - $c2.ord) == 'a'.ord - 'A'.ord +} diff --git a/challenge-328/feng-chang/raku/test.raku b/challenge-328/feng-chang/raku/test.raku new file mode 100755 index 0000000000..9f19950944 --- /dev/null +++ b/challenge-328/feng-chang/raku/test.raku @@ -0,0 +1,24 @@ +#!/bin/env raku + +# The Weekly Challenge 328 +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, Replace All ? +pwc-test './ch-1.raku', 'a?z', 'abz', 'Replace All ?: a?z => abz'; +pwc-test './ch-1.raku', 'pe?k', 'peak', 'Replace All ?: pe?k => peak'; +pwc-test './ch-1.raku', 'gra?te', 'grabte', 'Replace All ?: gra?te => grabte'; + +# Task 2, Good String +pwc-test './ch-2.raku', 'WeEeekly', 'Weekly', 'Good String: WeEeekly => Weekly'; +pwc-test './ch-2.raku', 'abBAdD', '', 'Good String: abBAdD => ""'; +pwc-test './ch-2.raku', 'abc', 'abc', 'Good String: abc => abc'; |
