diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-06-08 22:59:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-08 22:59:46 +0100 |
| commit | 8090e2dfa2afa2127025fe33be7e8089a33e5b34 (patch) | |
| tree | 3caef0e914928d22fea26f44f63abeacbbda8bed | |
| parent | 31fc5392efc4371a842668481242cd294a991690 (diff) | |
| parent | 7037de5a314d698cae4ae32de0a4c1e6299f9778 (diff) | |
| download | perlweeklychallenge-club-8090e2dfa2afa2127025fe33be7e8089a33e5b34.tar.gz perlweeklychallenge-club-8090e2dfa2afa2127025fe33be7e8089a33e5b34.tar.bz2 perlweeklychallenge-club-8090e2dfa2afa2127025fe33be7e8089a33e5b34.zip | |
Merge pull request #12144 from jaldhar/challenge-324
Challenge 324 by Jaldhar H. Vyas.
| -rw-r--r-- | challenge-324/jaldhar-h-vyas/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-324/jaldhar-h-vyas/perl/ch-1.pl | 11 | ||||
| -rwxr-xr-x | challenge-324/jaldhar-h-vyas/perl/ch-2.pl | 41 | ||||
| -rwxr-xr-x | challenge-324/jaldhar-h-vyas/raku/ch-1.raku | 15 | ||||
| -rwxr-xr-x | challenge-324/jaldhar-h-vyas/raku/ch-2.sh | 3 |
5 files changed, 71 insertions, 0 deletions
diff --git a/challenge-324/jaldhar-h-vyas/blog.txt b/challenge-324/jaldhar-h-vyas/blog.txt new file mode 100644 index 0000000000..de6d76ac84 --- /dev/null +++ b/challenge-324/jaldhar-h-vyas/blog.txt @@ -0,0 +1 @@ +https://www.braincells.com/perl/2025/06/perl_weekly_challenge_week_324.html diff --git a/challenge-324/jaldhar-h-vyas/perl/ch-1.pl b/challenge-324/jaldhar-h-vyas/perl/ch-1.pl new file mode 100755 index 0000000000..06351709d7 --- /dev/null +++ b/challenge-324/jaldhar-h-vyas/perl/ch-1.pl @@ -0,0 +1,11 @@ +#!/usr/bin/perl +use v5.38; + +my ($r, $c, @ints) = @ARGV; +my @output; + +for my $row (1 .. $r) { + push @output, [ splice @ints, 0, $c ]; +} + +say q{(}, (join q{, }, map { q{[} . (join q{, }, @{$_}) . q{]} } @output), q{)};
\ No newline at end of file diff --git a/challenge-324/jaldhar-h-vyas/perl/ch-2.pl b/challenge-324/jaldhar-h-vyas/perl/ch-2.pl new file mode 100755 index 0000000000..4e30f754d2 --- /dev/null +++ b/challenge-324/jaldhar-h-vyas/perl/ch-2.pl @@ -0,0 +1,41 @@ +#!/usr/bin/perl +use 5.030; +use warnings; + +sub combinations { + my @list = @{$_[0]}; + my $length = $_[1]; + + if ($length <= 1) { + return map [$_], @list; + } + + my @combos; + + for (my $i = 0; $i + $length <= scalar @list; $i++) { + my $val = $list[$i]; + my @rest = @list[$i + 1 .. $#list]; + for my $c (combinations(\@rest, $length - 1)) { + push @combos, [$val, @{$c}] ; + } + } + + return @combos; +} + +my @ints = @ARGV; +my $sum = 0; + +for my $i (1 .. scalar @ints) { + for my $combo (combinations(\@ints, $i)) { + my $total = 0; + + for my $j (@{$combo}) { + $total ^= $j; + } + + $sum += $total; + } +} + +say $sum; diff --git a/challenge-324/jaldhar-h-vyas/raku/ch-1.raku b/challenge-324/jaldhar-h-vyas/raku/ch-1.raku new file mode 100755 index 0000000000..bde30ddd80 --- /dev/null +++ b/challenge-324/jaldhar-h-vyas/raku/ch-1.raku @@ -0,0 +1,15 @@ +#!/usr/bin/raku + +sub MAIN( + $r, + $c, + *@ints +) { + my @output; + + for 1 .. $r { + @output.push(@ints.splice(0, $c)); + } + + say q{(}, @output.map({ q{[} ~ @$_.join(q{, }) ~ q{]} }).join(q{, }), q{)}; +}
\ No newline at end of file diff --git a/challenge-324/jaldhar-h-vyas/raku/ch-2.sh b/challenge-324/jaldhar-h-vyas/raku/ch-2.sh new file mode 100755 index 0000000000..24ba064209 --- /dev/null +++ b/challenge-324/jaldhar-h-vyas/raku/ch-2.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +raku -e '@*ARGS.combinations.map({[+^] $_}).sum.say' "$@" |
