diff options
| author | Scimon <simon.proctor@gmail.com> | 2025-08-26 10:42:04 +0100 |
|---|---|---|
| committer | Scimon <simon.proctor@gmail.com> | 2025-08-26 10:42:04 +0100 |
| commit | 96f32a6c4c7b023cbc8117c768ad0af573cc76bc (patch) | |
| tree | f1f4e94b651ac136f03607380705a3829269bd4d | |
| parent | 993ea6c728733372d0b64ff57c115d54a1e7ae14 (diff) | |
| download | perlweeklychallenge-club-96f32a6c4c7b023cbc8117c768ad0af573cc76bc.tar.gz perlweeklychallenge-club-96f32a6c4c7b023cbc8117c768ad0af573cc76bc.tar.bz2 perlweeklychallenge-club-96f32a6c4c7b023cbc8117c768ad0af573cc76bc.zip | |
PArt 2 complete
| -rwxr-xr-x[-rw-r--r--] | challenge-336/simon-proctor/raku/ch-2.raku | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/challenge-336/simon-proctor/raku/ch-2.raku b/challenge-336/simon-proctor/raku/ch-2.raku index 41448bbc4d..dbfd8eb218 100644..100755 --- a/challenge-336/simon-proctor/raku/ch-2.raku +++ b/challenge-336/simon-proctor/raku/ch-2.raku @@ -8,5 +8,32 @@ multi sub MAIN(:t(:$test)) is hidden-from-USAGE { 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; } |
