diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-08-25 01:48:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-25 01:48:19 +0100 |
| commit | 38ee4fc3ae489264dbacb37b2799c49e7593e3ed (patch) | |
| tree | 69b2e3a656ccd28faae94d567982ed0908fa248e | |
| parent | 1d5bc8dccdd09cd4a319a13a2fecabab8c15b577 (diff) | |
| parent | 084417737a1ea1ddbd8b86a92f5ccb0e872095d4 (diff) | |
| download | perlweeklychallenge-club-38ee4fc3ae489264dbacb37b2799c49e7593e3ed.tar.gz perlweeklychallenge-club-38ee4fc3ae489264dbacb37b2799c49e7593e3ed.tar.bz2 perlweeklychallenge-club-38ee4fc3ae489264dbacb37b2799c49e7593e3ed.zip | |
Merge pull request #12564 from arnesom/challenge-335-arne-sommer
week 335 Arne Sommer
| -rw-r--r-- | challenge-335/arne-sommer/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-335/arne-sommer/raku/ch-1.raku | 13 | ||||
| -rwxr-xr-x | challenge-335/arne-sommer/raku/ch-2.raku | 45 | ||||
| -rwxr-xr-x | challenge-335/arne-sommer/raku/common-characters | 13 | ||||
| -rwxr-xr-x | challenge-335/arne-sommer/raku/find-winner | 45 |
5 files changed, 117 insertions, 0 deletions
diff --git a/challenge-335/arne-sommer/blog.txt b/challenge-335/arne-sommer/blog.txt new file mode 100644 index 0000000000..b3f45a2085 --- /dev/null +++ b/challenge-335/arne-sommer/blog.txt @@ -0,0 +1 @@ +https://raku-musings.com/common-find.html
\ No newline at end of file diff --git a/challenge-335/arne-sommer/raku/ch-1.raku b/challenge-335/arne-sommer/raku/ch-1.raku new file mode 100755 index 0000000000..423b3fa202 --- /dev/null +++ b/challenge-335/arne-sommer/raku/ch-1.raku @@ -0,0 +1,13 @@ +#! /usr/bin/env raku + +unit sub MAIN (*@words where @words.elems > 0, :v(:$verbose)); + +my @bags = @words>>.comb>>.Bag; + +say ": Bags; { @bags.raku }" if $verbose; + +my $intersection = [(&)] @bags; + +say ": Common: { $intersection.raku }" if $verbose; + +say "(" ~ $intersection.kxxv.sort.map( '"' ~ * ~ '"' ).join(", ") ~ ")";
\ No newline at end of file diff --git a/challenge-335/arne-sommer/raku/ch-2.raku b/challenge-335/arne-sommer/raku/ch-2.raku new file mode 100755 index 0000000000..7998fc654d --- /dev/null +++ b/challenge-335/arne-sommer/raku/ch-2.raku @@ -0,0 +1,45 @@ +#! /usr/bin/env raku + +unit sub MAIN (*@moves where @moves.elems > 0 + && all(@moves) ~~/^<[012]> \, <[012]>$/, + :v(:$verbose)); + +my @board = [ [ '-', '-', '-' ], ['-', '-', '-'], ['-', '-', '-'] ]; + +my $player = 'A'; + +for @moves -> $move +{ + my ($x, $y) = $move.split(","); + + die "Position $x,$y already taken" unless @board[$x][$y] eq "-"; + + @board[$x][$y] = $player; + + $player = $player eq 'A' ?? 'B' !! 'A'; +} + +if $verbose +{ + say ": " ~ @board[0].join(" "); + say ": " ~ @board[1].join(" "); + say ": " ~ @board[2].join(" "); +} + +for 'A', 'B' -> $ab +{ + if all(@board[0;*]) eq $ab || + all(@board[1;*]) eq $ab || + all(@board[2;*]) eq $ab || + all(@board[*;0]) eq $ab || + all(@board[*;1]) eq $ab || + all(@board[*;2]) eq $ab || + @board[0][0] eq @board[1][1] eq @board[2][2] eq $ab || + @board[2][0] eq @board[1][1] eq @board[0][2] eq $ab + { + say $ab; + exit; + } +} + +say @moves.elems == 9 ?? 'Draw' !! 'Pending'; diff --git a/challenge-335/arne-sommer/raku/common-characters b/challenge-335/arne-sommer/raku/common-characters new file mode 100755 index 0000000000..423b3fa202 --- /dev/null +++ b/challenge-335/arne-sommer/raku/common-characters @@ -0,0 +1,13 @@ +#! /usr/bin/env raku + +unit sub MAIN (*@words where @words.elems > 0, :v(:$verbose)); + +my @bags = @words>>.comb>>.Bag; + +say ": Bags; { @bags.raku }" if $verbose; + +my $intersection = [(&)] @bags; + +say ": Common: { $intersection.raku }" if $verbose; + +say "(" ~ $intersection.kxxv.sort.map( '"' ~ * ~ '"' ).join(", ") ~ ")";
\ No newline at end of file diff --git a/challenge-335/arne-sommer/raku/find-winner b/challenge-335/arne-sommer/raku/find-winner new file mode 100755 index 0000000000..7998fc654d --- /dev/null +++ b/challenge-335/arne-sommer/raku/find-winner @@ -0,0 +1,45 @@ +#! /usr/bin/env raku + +unit sub MAIN (*@moves where @moves.elems > 0 + && all(@moves) ~~/^<[012]> \, <[012]>$/, + :v(:$verbose)); + +my @board = [ [ '-', '-', '-' ], ['-', '-', '-'], ['-', '-', '-'] ]; + +my $player = 'A'; + +for @moves -> $move +{ + my ($x, $y) = $move.split(","); + + die "Position $x,$y already taken" unless @board[$x][$y] eq "-"; + + @board[$x][$y] = $player; + + $player = $player eq 'A' ?? 'B' !! 'A'; +} + +if $verbose +{ + say ": " ~ @board[0].join(" "); + say ": " ~ @board[1].join(" "); + say ": " ~ @board[2].join(" "); +} + +for 'A', 'B' -> $ab +{ + if all(@board[0;*]) eq $ab || + all(@board[1;*]) eq $ab || + all(@board[2;*]) eq $ab || + all(@board[*;0]) eq $ab || + all(@board[*;1]) eq $ab || + all(@board[*;2]) eq $ab || + @board[0][0] eq @board[1][1] eq @board[2][2] eq $ab || + @board[2][0] eq @board[1][1] eq @board[0][2] eq $ab + { + say $ab; + exit; + } +} + +say @moves.elems == 9 ?? 'Draw' !! 'Pending'; |
