diff options
| author | Jaldhar H. Vyas <jaldhar@braincells.com> | 2025-09-07 23:03:45 -0400 |
|---|---|---|
| committer | Jaldhar H. Vyas <jaldhar@braincells.com> | 2025-09-07 23:03:45 -0400 |
| commit | 9594fefb52ca6f7ec80ddfaa2b85f08c9e96387c (patch) | |
| tree | 8112116cdc4d7f4fe4cb4eb02832f1a415b92b8c | |
| parent | 1d93bdf03f934443562da1fb88731936fa396f09 (diff) | |
| download | perlweeklychallenge-club-9594fefb52ca6f7ec80ddfaa2b85f08c9e96387c.tar.gz perlweeklychallenge-club-9594fefb52ca6f7ec80ddfaa2b85f08c9e96387c.tar.bz2 perlweeklychallenge-club-9594fefb52ca6f7ec80ddfaa2b85f08c9e96387c.zip | |
Challenge 337 by Jaldhar H. Vyas.
| -rw-r--r-- | challenge-337/jaldhar-h-vyas/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-337/jaldhar-h-vyas/perl/ch-1.pl | 14 | ||||
| -rwxr-xr-x | challenge-337/jaldhar-h-vyas/perl/ch-2.pl | 34 | ||||
| -rwxr-xr-x | challenge-337/jaldhar-h-vyas/raku/ch-1.raku | 13 | ||||
| -rwxr-xr-x | challenge-337/jaldhar-h-vyas/raku/ch-2.raku | 27 |
5 files changed, 89 insertions, 0 deletions
diff --git a/challenge-337/jaldhar-h-vyas/blog.txt b/challenge-337/jaldhar-h-vyas/blog.txt new file mode 100644 index 0000000000..23cc9aac4d --- /dev/null +++ b/challenge-337/jaldhar-h-vyas/blog.txt @@ -0,0 +1 @@ +https://www.braincells.com/perl/2025/09/perl_weekly_challenge_week_337.html diff --git a/challenge-337/jaldhar-h-vyas/perl/ch-1.pl b/challenge-337/jaldhar-h-vyas/perl/ch-1.pl new file mode 100755 index 0000000000..a4c9fe3f49 --- /dev/null +++ b/challenge-337/jaldhar-h-vyas/perl/ch-1.pl @@ -0,0 +1,14 @@ +#!/usr/bin/perl +use v5.38; +use warnings; +use builtin qw/ indexed /; +no warnings qw/ experimental::builtin experimental::for_list /; + +my @num1 = @ARGV; +my %sorted; + +foreach my ($k, $v) (reverse indexed sort { $a <=> $b } @num1) { + $sorted{$k} //= $v; +} + +say q{(}, (join q{, }, map { $sorted{$_} } @num1), q{)}; diff --git a/challenge-337/jaldhar-h-vyas/perl/ch-2.pl b/challenge-337/jaldhar-h-vyas/perl/ch-2.pl new file mode 100755 index 0000000000..aa909c776d --- /dev/null +++ b/challenge-337/jaldhar-h-vyas/perl/ch-2.pl @@ -0,0 +1,34 @@ +#!/usr/bin/perl +use v5.38; +use warnings; +use builtin qw/ indexed /; +no warnings qw/ experimental::builtin experimental::for_list /; + +sub count(@matrix) { + my $count = 0; + + for my $row (@matrix) { + $count += scalar grep { $_ % 2 } @{$row}; + } + + return $count; +} + +my ($row, $col, @locations) = @ARGV; + +my @matrix; +for my $i (0 .. $row - 1) { + push @matrix, [ (0) x $col ]; +} + +for my $location (@locations) { + my ($r, $c) = split /,/, $location; + for (@{$matrix[$r]}[0 .. $col - 1]) { + $_++; + } + for (@matrix[0 .. $row - 1]->[$c]) { + $_++; + } +} + +say count(@matrix); diff --git a/challenge-337/jaldhar-h-vyas/raku/ch-1.raku b/challenge-337/jaldhar-h-vyas/raku/ch-1.raku new file mode 100755 index 0000000000..8f5157e224 --- /dev/null +++ b/challenge-337/jaldhar-h-vyas/raku/ch-1.raku @@ -0,0 +1,13 @@ +#!/usr/bin/raku + +sub MAIN( + *@num1 +) { + my %sorted; + + for @num1.sort({ $^a <=> $^b }).kv.reverse -> $k, $v { + %sorted{$k} //= $v; + } + + say q{(}, @num1.map({ %sorted{$_} }).join(q{, }), q{)}; +}
\ No newline at end of file diff --git a/challenge-337/jaldhar-h-vyas/raku/ch-2.raku b/challenge-337/jaldhar-h-vyas/raku/ch-2.raku new file mode 100755 index 0000000000..67b75db335 --- /dev/null +++ b/challenge-337/jaldhar-h-vyas/raku/ch-2.raku @@ -0,0 +1,27 @@ +#!/usr/bin/raku + +sub count(@matrix) { + my $count = 0; + + for @matrix -> $row { + $count += $row.grep({ $_ mod 2 }).elems; + } + + return $count; +} + +sub MAIN( + $row, + $col, + *@locations +) { + my @matrix = [0 xx $col] xx $row; + + for @locations -> $location { + my ($r, $c) = $location.split(',')».Int; + @matrix[$r;*]»++; + @matrix[*;$c]»++ ; + } + + count(@matrix).say; +}
\ No newline at end of file |
