diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-08-26 10:50:22 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-26 10:50:22 +0100 |
| commit | 1b7b044290aae025ab151f177927432f39ef9a02 (patch) | |
| tree | 76ecbe026f19bf9c9bdc49e3a9d5e2bd49f32cc3 | |
| parent | cfe111699674dcbdae6a9172888ec4a0cf5ca4c1 (diff) | |
| parent | 982ed030ab801d3e258a00264d2d44a0030920a9 (diff) | |
| download | perlweeklychallenge-club-1b7b044290aae025ab151f177927432f39ef9a02.tar.gz perlweeklychallenge-club-1b7b044290aae025ab151f177927432f39ef9a02.tar.bz2 perlweeklychallenge-club-1b7b044290aae025ab151f177927432f39ef9a02.zip | |
Merge pull request #12578 from seaker/master
challenge 336, raku solutions
| -rwxr-xr-x | challenge-336/feng-chang/raku/ch-1.raku | 5 | ||||
| -rwxr-xr-x | challenge-336/feng-chang/raku/ch-2.raku | 12 | ||||
| -rwxr-xr-x | challenge-336/feng-chang/raku/test.raku | 28 |
3 files changed, 45 insertions, 0 deletions
diff --git a/challenge-336/feng-chang/raku/ch-1.raku b/challenge-336/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..b911848781 --- /dev/null +++ b/challenge-336/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +unit sub MAIN(*@ints); + +put @ints.Bag.values.reduce(&infix:<gcd>) > 1; diff --git a/challenge-336/feng-chang/raku/ch-2.raku b/challenge-336/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..858f43b203 --- /dev/null +++ b/challenge-336/feng-chang/raku/ch-2.raku @@ -0,0 +1,12 @@ +#!/bin/env raku + +unit sub MAIN(*@scores); + +my @stack; +for @scores { + when Int { @stack.push: $_ }; + when 'C' { @stack.pop }; + when 'D' { @stack.push: @stack.tail * 2 }; + when '+' { @stack.push: @stack.tail(2).sum }; +} +put @stack.sum; diff --git a/challenge-336/feng-chang/raku/test.raku b/challenge-336/feng-chang/raku/test.raku new file mode 100755 index 0000000000..c6cff6cbcc --- /dev/null +++ b/challenge-336/feng-chang/raku/test.raku @@ -0,0 +1,28 @@ +#!/bin/env raku + +# The Weekly Challenge 336 +use Test; + +sub pwc-test(Str:D $script, Bool :$deeply? = False, *@input) { + my ($expect, $assertion) = @input.splice(*-2, 2); + my $p = run $script, |@input, :out; + if $deeply { + is-deeply $p.out.slurp(:close).chomp.words.Bag, $expect, $assertion; + } else { + is $p.out.slurp(:close).chomp, $expect, $assertion; + } +} + +# Task 1, Equal Group +pwc-test './ch-1.raku', <1 1 2 2 2 2>, 'True', 'Equal Group: (1,1,2,2,2,2) => true'; +pwc-test './ch-1.raku', <1 1 1 2 2 2 3 3>, 'False', 'Equal Group: (1,1,1,2,2,2,3,3) => false'; +pwc-test './ch-1.raku', <5 5 5 5 5 5 7 7 7 7 7 7>, 'True', 'Equal Group: (5,5,5,5,5,5,7,7,7,7,7,7) => true'; +pwc-test './ch-1.raku', <1 2 3 4>, 'False', 'Equal Group: (1,2,3,4) => false'; +pwc-test './ch-1.raku', <8 8 9 9 10 10 11 11>, 'True', 'Equal Group: (8,8,9,9,10,10,11,11) => true'; + +# Task 2, Final Score +pwc-test './ch-2.raku', <5 2 C D +>, 30, 'Final Score: ("5","2","C","D","+") => 30'; +pwc-test './ch-2.raku', <5 -2 4 C D 9 + +>, 27, 'Final Score: ("5","-2","4","C","D","9","+","+") => 27'; +pwc-test './ch-2.raku', <7 D D C + 3>, 45, 'Final Score: ("7","D","D","C","+","3") => 45'; +pwc-test './ch-2.raku', <-- -5 -10 + D C +>, -55, 'Final Score: ("-5","-10","+","D","C","+") => -55'; +pwc-test './ch-2.raku', <3 6 + D C 8 + D -2 C +>, 128, 'Final Score: ("3","6","+","D","C","8","+","D","-2","C","+") => 128'; |
