diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-08-19 11:48:00 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-19 11:48:00 +0100 |
| commit | 2c9ff2db5d7fd9d5a6be3bac4f99093a941b2aff (patch) | |
| tree | ab304d28db02e86e5eb65c8736a9d8a1a9fc3728 | |
| parent | 69be3a3fcc13b3ca8ef4bf1ecd7440ad69cf9426 (diff) | |
| parent | dca58b342f577b02e5f39128e695bf1f41c114e0 (diff) | |
| download | perlweeklychallenge-club-2c9ff2db5d7fd9d5a6be3bac4f99093a941b2aff.tar.gz perlweeklychallenge-club-2c9ff2db5d7fd9d5a6be3bac4f99093a941b2aff.tar.bz2 perlweeklychallenge-club-2c9ff2db5d7fd9d5a6be3bac4f99093a941b2aff.zip | |
Merge pull request #12535 from seaker/master
challenge 335, raku solutions
| -rwxr-xr-x | challenge-335/feng-chang/raku/ch-1.raku | 5 | ||||
| -rwxr-xr-x | challenge-335/feng-chang/raku/ch-2.raku | 24 | ||||
| -rwxr-xr-x | challenge-335/feng-chang/raku/test.raku | 33 |
3 files changed, 62 insertions, 0 deletions
diff --git a/challenge-335/feng-chang/raku/ch-1.raku b/challenge-335/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..50ddb4f4be --- /dev/null +++ b/challenge-335/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +unit sub MAIN(*@words); + +put @words.map({ .comb.Bag }).reduce(&infix:<(&)>).map({ .key xx .value }).flat.sort; diff --git a/challenge-335/feng-chang/raku/ch-2.raku b/challenge-335/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..4c41bd5ae5 --- /dev/null +++ b/challenge-335/feng-chang/raku/ch-2.raku @@ -0,0 +1,24 @@ +#!/bin/env raku + +unit sub MAIN(Str:D $moves); + +use MONKEY-SEE-NO-EVAL; + +my @board = ('_' xx 3).Array xx 3; + +my @moves = EVAL $moves; +@board[@moves[$_;0];@moves[$_;1]] = <A B>[$_ % 2] for ^+@moves; + +my $any-row-col-diagonal = ( + |(@board[$_ ].all for ^3), + |(@board[*;$_].all for ^3), + (@board[$_;$_ ] for ^3).all, + (@board[$_;2-$_] for ^3).all, +).any; + +put do given @board { + when $any-row-col-diagonal eq 'A' { 'A' } + when $any-row-col-diagonal eq 'B' { 'B' } + when @board[*;*].any eq '_' { 'Pending' } + default { 'Draw'} +} diff --git a/challenge-335/feng-chang/raku/test.raku b/challenge-335/feng-chang/raku/test.raku new file mode 100755 index 0000000000..764a6f9d69 --- /dev/null +++ b/challenge-335/feng-chang/raku/test.raku @@ -0,0 +1,33 @@ +#!/bin/env raku + +# The Weekly Challenge 335 +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, Common Characters +pwc-test './ch-1.raku', <bella label roller>, 'e l l', 'Common Characters: ("bella","label","roller") => ("e", "l", "l")'; +pwc-test './ch-1.raku', <cool lock cook>, 'c o', 'Common Characters: ("cool","lock","cook") => ("c", "o")'; +pwc-test './ch-1.raku', <hello world pole>, 'l o', 'Common Characters: ("hello","world","pole") => ("l", "o")'; +pwc-test './ch-1.raku', <abc def ghi>, '', 'Common Characters: ("abc","def","ghi") => ()'; +pwc-test './ch-1.raku', <aab aac aaa>, 'a a', 'Common Characters: ("aab","aac","aaa") => ("a", "a")'; + +# Task 2, Find Winner +pwc-test './ch-2.raku', '[0,0],[1,0],[1,1],[1,2],[2,2]', 'A', + 'Find Winner: [0,0],[1,0],[1,1],[1,2],[2,2] => A'; +pwc-test './ch-2.raku', '[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]', 'B', + 'Find Winner: [0,0],[1,1],[0,1],[0,2],[1,0],[2,0] => B'; +pwc-test './ch-2.raku', '[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]', 'Draw', + 'Find Winner: [0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2] => Draw'; +pwc-test './ch-2.raku', '[0,0],[1,1]', 'Pending', + 'Find Winner: [0,0],[1,1] => Pending'; +pwc-test './ch-2.raku', '[1,1],[0,0],[2,2],[0,1],[1,0],[0,2]', 'B', + 'Find Winner: [1,1],[0,0],[2,2],[0,1],[1,0],[0,2] => B'; |
