diff options
| author | Scimon <simon.proctor@gmail.com> | 2025-07-14 10:58:37 +0100 |
|---|---|---|
| committer | Scimon <simon.proctor@gmail.com> | 2025-07-14 10:58:37 +0100 |
| commit | c2878fb25dd8f743c371fe3263519e91be6c3ae2 (patch) | |
| tree | 6a670c1ff858efe936721d783e19ba43c4e4320d | |
| parent | 6345c73edaafe1c1252e99cf8991c8fc27890445 (diff) | |
| download | perlweeklychallenge-club-c2878fb25dd8f743c371fe3263519e91be6c3ae2.tar.gz perlweeklychallenge-club-c2878fb25dd8f743c371fe3263519e91be6c3ae2.tar.bz2 perlweeklychallenge-club-c2878fb25dd8f743c371fe3263519e91be6c3ae2.zip | |
Challenge accepted
| -rwxr-xr-x | challenge-330/simon-proctor/raku/ch-1.raku | 37 | ||||
| -rwxr-xr-x | challenge-330/simon-proctor/raku/ch-2.raku | 39 |
2 files changed, 76 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..7defc70037 --- /dev/null +++ b/challenge-330/simon-proctor/raku/ch-1.raku @@ -0,0 +1,37 @@ +#!/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) { + $str = loop-strip( $str, / \D\d / ); + $str = loop-strip( $str, /^ \d / ); + return $str; +} + +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; +} |
