diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-07-15 10:53:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-15 10:53:39 +0100 |
| commit | 33872634c313eac06f9f1ac6e4277516071fbdcb (patch) | |
| tree | 14e625e9fbc8fd76c2a16354a0163c146261bd1e | |
| parent | 0889b4dc9a263f973986e0a6711676ce2d177b0a (diff) | |
| parent | 19d744aab2edc6987db102b870b35bf4f2461b71 (diff) | |
| download | perlweeklychallenge-club-33872634c313eac06f9f1ac6e4277516071fbdcb.tar.gz perlweeklychallenge-club-33872634c313eac06f9f1ac6e4277516071fbdcb.tar.bz2 perlweeklychallenge-club-33872634c313eac06f9f1ac6e4277516071fbdcb.zip | |
Merge pull request #12344 from Scimon/master
Challenge accepted
| -rwxr-xr-x | challenge-330/simon-proctor/raku/ch-1.raku | 35 | ||||
| -rwxr-xr-x | challenge-330/simon-proctor/raku/ch-2.raku | 39 |
2 files changed, 74 insertions, 0 deletions
diff --git a/challenge-330/simon-proctor/raku/ch-1.raku b/challenge-330/simon-proctor/raku/ch-1.raku new file mode 100755 index 0000000000..f37cecd14d --- /dev/null +++ b/challenge-330/simon-proctor/raku/ch-1.raku @@ -0,0 +1,35 @@ +#!/usr/bin/env raku + +subset ValidInput of Str where /^ <[a..z 0..9]>+ $/; + +multi sub MAIN(:t(:$test)) is hidden-from-USAGE { + use Test; + is clear-digits("cab12"),"c"; + is clear-digits("xy99"), ""; + is clear-digits("pa1erl"), "perl"; + is clear-digits("1234a"), "a"; + is clear-digits("a123"),""; + done-testing; +} + +sub clear-digits(ValidInput $str is copy) { + loop-strip( $str, / \D?\d / ); +} + +sub loop-strip( $str is copy, $regex ) { + my $new; + repeat { + $new = $str; + $str ~~ s/ $regex //; + } while $new ne $str; + return $new; +} + +#|( Given a string of letters and number +remove all the numbers and the left most +letter found before each one) +multi sub MAIN( + ValidInput $str #= String made of letters and numbers +) { + clear-digits($str).say; +} diff --git a/challenge-330/simon-proctor/raku/ch-2.raku b/challenge-330/simon-proctor/raku/ch-2.raku new file mode 100755 index 0000000000..d401eda200 --- /dev/null +++ b/challenge-330/simon-proctor/raku/ch-2.raku @@ -0,0 +1,39 @@ +#!/usr/bin/env raku + +subset ValidWord of Str where /^ <[a..z A..Z]>+ $/; +subset ValidSentence of Str where { all($_.split(" ")) ~~ ValidWord }; + +multi sub MAIN(:t(:$test)) is hidden-from-USAGE { + use Test; + is title-caps("PERL IS gREAT"), "Perl is Great"; + is title-caps("THE weekly challenge"), "The Weekly Challenge"; + is title-caps("YoU ARE A stAR"), "You Are a Star"; + done-testing; +} + +sub title-caps(ValidSentence $str is copy) { + $str + .split(" ") + .map(*.lc) + .map( -> $a { $a.codes > 2 ?? $a.tc !! $a } ) + .join(" "); +} + +#|(Accepts a string made of +upper and lower case letters. Outputs the +sentence nicely capitalised) +multi sub MAIN( + ValidSentence $str #= Sentence made or letters in both cases +) { + title-caps($str).say; +} + +#|(Accepts a list of strings made of +upper and lower case letters. Outputs the +sentence nicely capitalised +) +multi sub MAIN( + *@words where all(@words) ~~ ValidWord #= List of words +) { + title-caps(@words.join(" ")).say; +} |
