aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Ferrone <zapwai@gmail.com>2025-06-02 12:33:04 -0400
committerGitHub <noreply@github.com>2025-06-02 12:33:04 -0400
commitb296c00764a2e47cdc1c094e1599d90f04ac6ea0 (patch)
treed07b5e8054b56bb8328a2cf2161d4324000fc9cf
parentb0159e77cc4e56da3a5a1c86d5769c652bcc887e (diff)
downloadperlweeklychallenge-club-b296c00764a2e47cdc1c094e1599d90f04ac6ea0.tar.gz
perlweeklychallenge-club-b296c00764a2e47cdc1c094e1599d90f04ac6ea0.tar.bz2
perlweeklychallenge-club-b296c00764a2e47cdc1c094e1599d90f04ac6ea0.zip
week 324
-rw-r--r--challenge-324/zapwai/perl/ch-1.pl24
-rw-r--r--challenge-324/zapwai/perl/ch-2.pl29
2 files changed, 53 insertions, 0 deletions
diff --git a/challenge-324/zapwai/perl/ch-1.pl b/challenge-324/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..3268d8fa47
--- /dev/null
+++ b/challenge-324/zapwai/perl/ch-1.pl
@@ -0,0 +1,24 @@
+use v5.40;
+
+sub proc($r, $c, @ints) {
+ say "Input: \@ints = @ints, \$r = $r, \$c = $c";
+ die "wrong dimensions for this data" if (@ints != $r * $c);
+ my $cell = 0;
+ my @o;
+ for my $row (1 .. $r) {
+ my @x;
+ for my $col (1 .. $c) {
+ push @x, $ints[$cell++];
+ }
+ push @o, \@x;
+ }
+ say "Output: ";
+ say "@$_" foreach (@o);
+}
+
+my @ints = (1, 2, 3, 4); my $r = 2; my $c = 2;
+proc($r, $c, @ints);
+@ints = (1, 2, 3); $r = 1; $c = 3;
+proc($r, $c, @ints);
+@ints = (1, 2, 3, 4); $r = 4; $c = 1;
+proc($r, $c, @ints);
diff --git a/challenge-324/zapwai/perl/ch-2.pl b/challenge-324/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..38aec00ec7
--- /dev/null
+++ b/challenge-324/zapwai/perl/ch-2.pl
@@ -0,0 +1,29 @@
+use v5.40;
+use Data::PowerSet qw( powerset );
+
+sub xorsum(@a) {
+ return $a[0] if (@a == 1);
+ my $sum = 0;
+ $sum ^= $_ for (@a);
+ return $sum;
+}
+
+sub proc(@ints) {
+ say "Input: \@ints = @ints";
+ my $pow = powerset(@ints);
+ my $tot = 0;
+ for my $p (@$pow) {
+ #print "\t\t@$p\t:";
+ my $x = xorsum(@$p);
+ #say "xorsum: $x";
+ $tot += $x;
+ }
+ say "Output: $tot";
+}
+
+my @ints = (1,3);
+proc(@ints);
+@ints = (5,1,6);
+proc(@ints);
+@ints = (3, 4, 5, 6, 7, 8);
+proc(@ints);