aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-336/simon-proctor/raku/ch-1.raku23
-rwxr-xr-xchallenge-336/simon-proctor/raku/ch-2.raku39
2 files changed, 62 insertions, 0 deletions
diff --git a/challenge-336/simon-proctor/raku/ch-1.raku b/challenge-336/simon-proctor/raku/ch-1.raku
new file mode 100755
index 0000000000..c14f3870b9
--- /dev/null
+++ b/challenge-336/simon-proctor/raku/ch-1.raku
@@ -0,0 +1,23 @@
+#!/usr/bin/env raku
+
+multi sub MAIN(:t(:$test)) is hidden-from-USAGE {
+ use Test;
+ is equal-group(1,1,2,2,2,2), True;
+ is equal-group(1,2,1,2,2,2), True;
+ is equal-group(1,1,1,2,2,2,3,3), False;
+ is equal-group(5,5,5,5,5,5,7,7,7,7,7,7), True;
+ is equal-group(1,2,3,4), False;
+ is equal-group(8,8,9,9,10,10,11,11), True;
+ done-testing;
+}
+
+multi sub MAIN(*@args where all(@args) ~~ Int() ) {
+ equal-group(|@args).say;
+}
+
+sub equal-group(*@args where all(@args) ~~ Int() ) {
+ my $bag = @args.Bag;
+ my $min-len = $bag.values.min;
+ return False if $min-len < 2;
+ return so all( $bag.values >>%%>> $min-len );
+}
diff --git a/challenge-336/simon-proctor/raku/ch-2.raku b/challenge-336/simon-proctor/raku/ch-2.raku
new file mode 100755
index 0000000000..dbfd8eb218
--- /dev/null
+++ b/challenge-336/simon-proctor/raku/ch-2.raku
@@ -0,0 +1,39 @@
+#!/usr/bin/env raku
+
+multi sub MAIN(:t(:$test)) is hidden-from-USAGE {
+ use Test;
+ is final-score("5","2","C","D","+"), 30;
+ is final-score("5","-2","4","C","D","9","+","+"), 27;
+ is final-score("7","D","D","C","+","3"), 45;
+ is final-score("-5","-10","+","D","C","+"), -55;
+ is final-score("3","6","+","D","C","8","+","D","-2","C","+"), 128;
+ done-testing;
+}
+
+subset ValidScore of Str where /^ "-"?\d+ || "D" || "C" || "+" $/;
+
+multi sub MAIN(*@scores where all(@scores) ~~ ValidScore ) {
+ final-score(|@scores).say;
+}
+
+sub final-score(*@scores where all(@scores) ~~ ValidScore ) {
+ my @results = [];
+ for @scores -> $score {
+ given $score {
+ when ( 'C' ) {
+ @results.pop;
+ succeed;
+ }
+ when ( "D") {
+ @results.push( @results[*-1] * 2);
+ succeed;
+ }
+ when ("+") {
+ @results.push( @results[*-1] + @results[*-2] );
+ succeed;
+ }
+ default { @results.push($score.Int) }
+ }
+ }
+ return [+] @results;
+}