aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Sommer <arne@bbop.org>2025-08-24 19:57:14 +0200
committerArne Sommer <arne@bbop.org>2025-08-24 19:57:14 +0200
commit084417737a1ea1ddbd8b86a92f5ccb0e872095d4 (patch)
treeb7678bff086fbe585dafe9c71e43405dd696f9c3
parent5c71e1ef11ec1d5fce6fd6d0d3ea3230e3d82b68 (diff)
downloadperlweeklychallenge-club-084417737a1ea1ddbd8b86a92f5ccb0e872095d4.tar.gz
perlweeklychallenge-club-084417737a1ea1ddbd8b86a92f5ccb0e872095d4.tar.bz2
perlweeklychallenge-club-084417737a1ea1ddbd8b86a92f5ccb0e872095d4.zip
week 335 Arne Sommer
-rw-r--r--challenge-335/arne-sommer/blog.txt1
-rwxr-xr-xchallenge-335/arne-sommer/raku/ch-1.raku13
-rwxr-xr-xchallenge-335/arne-sommer/raku/ch-2.raku45
-rwxr-xr-xchallenge-335/arne-sommer/raku/common-characters13
-rwxr-xr-xchallenge-335/arne-sommer/raku/find-winner45
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';