diff options
| -rw-r--r-- | challenge-335/jaldhar-h-vyas/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-335/jaldhar-h-vyas/perl/ch-1.pl | 32 | ||||
| -rwxr-xr-x | challenge-335/jaldhar-h-vyas/perl/ch-2.pl | 39 | ||||
| -rwxr-xr-x | challenge-335/jaldhar-h-vyas/raku/ch-1.sh | 3 | ||||
| -rwxr-xr-x | challenge-335/jaldhar-h-vyas/raku/ch-2.raku | 40 |
5 files changed, 115 insertions, 0 deletions
diff --git a/challenge-335/jaldhar-h-vyas/blog.txt b/challenge-335/jaldhar-h-vyas/blog.txt new file mode 100644 index 0000000000..d2b57b74c1 --- /dev/null +++ b/challenge-335/jaldhar-h-vyas/blog.txt @@ -0,0 +1 @@ +https://www.braincells.com/perl/2025/08/perl_weekly_challenge_week_335.html diff --git a/challenge-335/jaldhar-h-vyas/perl/ch-1.pl b/challenge-335/jaldhar-h-vyas/perl/ch-1.pl new file mode 100755 index 0000000000..dfd7d701c0 --- /dev/null +++ b/challenge-335/jaldhar-h-vyas/perl/ch-1.pl @@ -0,0 +1,32 @@ +#!/usr/bin/perl +use 5.038; +use warnings; + +sub intersection($arr1, $arr2) { + my %count; + + for my $elem (@$arr1) { + $count{$elem}++; + } + + my @result; + + for my $elem (@$arr2) { + if ($count{$elem}) { + push @result, $elem; + $count{$elem}--; + } + } + + return @result; +} + +my (@words) = @ARGV; + +my @letters = split //, shift @words; + +for my $word (@words) { + @letters = intersection(\@letters, [split //, $word]); +} + +say q{(}, (join q{, }, map { "\"$_\"" } sort @letters ), q{)};
\ No newline at end of file diff --git a/challenge-335/jaldhar-h-vyas/perl/ch-2.pl b/challenge-335/jaldhar-h-vyas/perl/ch-2.pl new file mode 100755 index 0000000000..43e870f01a --- /dev/null +++ b/challenge-335/jaldhar-h-vyas/perl/ch-2.pl @@ -0,0 +1,39 @@ +#!/usr/bin/perl +use 5.038; +use warnings; + +sub isWinner($player) { + return grep { $_ == $player } (33, 303, 3003, 1110, 1113, 1116); +} + +my (@moves) = @ARGV; +my $A = 0; +my $B = 0; +my $result = 'Pending'; + +for my $turn (keys @moves) { + my ($row, $col) = split q{,}, $moves[$turn]; + + if ($turn % 2) { + $B += 10 ** ($row + 1) + $col; + if (isWinner($B)) { + $result = 'B'; + last; + } + } + + else { + $A += 10 ** ($row + 1) + $col; + if (isWinner($A)) { + $result = 'A'; + last; + } + } + + if ($turn == 8) { + $result = 'Draw'; + last; + } +} + +say $result; diff --git a/challenge-335/jaldhar-h-vyas/raku/ch-1.sh b/challenge-335/jaldhar-h-vyas/raku/ch-1.sh new file mode 100755 index 0000000000..65e82ca80c --- /dev/null +++ b/challenge-335/jaldhar-h-vyas/raku/ch-1.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +raku -e 'say q{(},([∩] @*ARGS.map({.comb.Bag})).map({"\"{.key}\""xx.value}).sort.join(q{, }),q{)}' "$@"
\ No newline at end of file diff --git a/challenge-335/jaldhar-h-vyas/raku/ch-2.raku b/challenge-335/jaldhar-h-vyas/raku/ch-2.raku new file mode 100755 index 0000000000..8508a53b7a --- /dev/null +++ b/challenge-335/jaldhar-h-vyas/raku/ch-2.raku @@ -0,0 +1,40 @@ +#!/usr/bin/raku + +sub isWinner($player) { + return (33, 303, 3003, 1110, 1113, 1116).grep($player).so; +} + +sub MAIN( + *@moves +) { + my $A = 0; + my $B = 0; + my $result = 'Pending'; + + for @moves.kv -> $turn, $square { + my ($row, $col) = $square.split(q{,})».Int; + + if $turn %% 2 { + $A += 10 ** ($row + 1) + $col; + if isWinner($A) { + $result = 'A'; + last; + } + } + + else { + $B += 10 ** ($row + 1) + $col; + if isWinner($B) { + $result = 'B'; + last; + } + } + + if $turn == 8 { + $result = 'Draw'; + last; + } + } + + say $result; +}
\ No newline at end of file |
