From 7037de5a314d698cae4ae32de0a4c1e6299f9778 Mon Sep 17 00:00:00 2001 From: "Jaldhar H. Vyas" Date: Sun, 8 Jun 2025 01:02:17 -0400 Subject: Challenge 324 by Jaldhar H. Vyas. --- challenge-324/jaldhar-h-vyas/blog.txt | 1 + challenge-324/jaldhar-h-vyas/perl/ch-1.pl | 11 ++++++++ challenge-324/jaldhar-h-vyas/perl/ch-2.pl | 41 +++++++++++++++++++++++++++++ challenge-324/jaldhar-h-vyas/raku/ch-1.raku | 15 +++++++++++ challenge-324/jaldhar-h-vyas/raku/ch-2.sh | 3 +++ 5 files changed, 71 insertions(+) create mode 100644 challenge-324/jaldhar-h-vyas/blog.txt create mode 100755 challenge-324/jaldhar-h-vyas/perl/ch-1.pl create mode 100755 challenge-324/jaldhar-h-vyas/perl/ch-2.pl create mode 100755 challenge-324/jaldhar-h-vyas/raku/ch-1.raku create mode 100755 challenge-324/jaldhar-h-vyas/raku/ch-2.sh 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' "$@" -- cgit