aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScimon <simon.proctor@gmail.com>2025-07-07 11:21:41 +0100
committerScimon <simon.proctor@gmail.com>2025-07-07 11:21:41 +0100
commit1ace3855f596551c072db7cf8d0e2fd67ee26525 (patch)
tree293e37f2bb1d1cd18ab3429f0e88e34900c622ee
parentbd7fce4bd5d085c209a213f2daca1e79799c9e87 (diff)
downloadperlweeklychallenge-club-1ace3855f596551c072db7cf8d0e2fd67ee26525.tar.gz
perlweeklychallenge-club-1ace3855f596551c072db7cf8d0e2fd67ee26525.tar.bz2
perlweeklychallenge-club-1ace3855f596551c072db7cf8d0e2fd67ee26525.zip
Challenge 329 done. Blog on Friday.
-rwxr-xr-xchallenge-329/simon-proctor/raku/ch-1.raku25
-rwxr-xr-xchallenge-329/simon-proctor/raku/ch-2.raku35
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;
+}