diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-07-08 17:00:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-08 17:00:14 +0100 |
| commit | 480fcf74548a2673941fe12eef7ba747bcec979f (patch) | |
| tree | a67e487e558b5df13625e253ac8d5c45a87f26f0 | |
| parent | 4c78918f0f706124d2698136626391cc142e2a92 (diff) | |
| parent | 1ace3855f596551c072db7cf8d0e2fd67ee26525 (diff) | |
| download | perlweeklychallenge-club-480fcf74548a2673941fe12eef7ba747bcec979f.tar.gz perlweeklychallenge-club-480fcf74548a2673941fe12eef7ba747bcec979f.tar.bz2 perlweeklychallenge-club-480fcf74548a2673941fe12eef7ba747bcec979f.zip | |
Merge pull request #12300 from Scimon/master
Challenge 329 done. Blog on Friday.
| -rwxr-xr-x | challenge-329/simon-proctor/raku/ch-1.raku | 25 | ||||
| -rwxr-xr-x | challenge-329/simon-proctor/raku/ch-2.raku | 35 |
2 files changed, 60 insertions, 0 deletions
diff --git a/challenge-329/simon-proctor/raku/ch-1.raku b/challenge-329/simon-proctor/raku/ch-1.raku new file mode 100755 index 0000000000..cde10f9067 --- /dev/null +++ b/challenge-329/simon-proctor/raku/ch-1.raku @@ -0,0 +1,25 @@ +#!/usr/bin/env raku + +# Tests fired if called with test parameter +multi sub MAIN(:t(:$test)) is hidden-from-USAGE { + use Test; + is counter-string("the1weekly2challenge2"), (1,2); + is counter-string("go21od1lu5c7k"), (21,1,5,7); + is counter-string("4p3e2r1l"), (4,3,2,1); + done-testing; +} + +subset ValidInput of Str where /^ <[a..z 0..9]>+ $/; + +sub counter-string( ValidInput $in is copy ) { + $in ~~ s:g/ (<[a..z]>) / /; + return $in.split(/" "+/).grep(* !~~ "").unique.map(*.Int); +} + +#|(Given a string made of lowercase letter and numbers +print a list of the unique numbers in it in order) +multi sub MAIN ( + ValidInput $str #= A string made up of lowercase letters and number +) { + counter-string($str).join(", ").say; +} diff --git a/challenge-329/simon-proctor/raku/ch-2.raku b/challenge-329/simon-proctor/raku/ch-2.raku new file mode 100755 index 0000000000..ae0d16130a --- /dev/null +++ b/challenge-329/simon-proctor/raku/ch-2.raku @@ -0,0 +1,35 @@ +#!/usr/bin/env raku + +# Tests fired if called with test parameter +multi sub MAIN(:t(:$test)) is hidden-from-USAGE { + use Test; + is nice-string("YaaAho"), "aaA"; + is nice-string("cC"), "cC"; + is nice-string("A"), ""; + done-testing; +} + +subset ValidInput of Str where m/^ <[a..z A..Z]>+ $/; + +sub nice-string( ValidInput $str ) { + my @letters = $str.comb; + my $upper = @letters ∩ ("A".."Z"); + my $lower = @letters ∩ ("a".."z"); + my %both; + for "a".."z" -> $str { + if ($str.uc ∈ $upper) && ($str ∈ $lower) { + %both{$str} = True; + %both{$str.uc} = True; + } + } + return @letters.grep( { %both{$_} } ).join(""); +} + +#|(Given a string made of upper and lower case +letter print the string with any letters not +included in both cases removed) +multi sub MAIN( + ValidInput $str #= A String made of lower and uppercase letters +) { + nice-string($str).say; +} |
