diff options
| -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; +} |
