aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Ferrone <zapwai@gmail.com>2023-03-23 23:15:17 -0400
committerDavid Ferrone <zapwai@gmail.com>2023-03-23 23:15:17 -0400
commit912a6af07557d35fa43ecf8b66a53c3eca58ddcc (patch)
treef55ad50fb942dfc5411bfe81c5f7ea78ae75f52d
parent9c5cd2108a8f6cf8b793c28051fdf8d767a4c8a9 (diff)
downloadperlweeklychallenge-club-912a6af07557d35fa43ecf8b66a53c3eca58ddcc.tar.gz
perlweeklychallenge-club-912a6af07557d35fa43ecf8b66a53c3eca58ddcc.tar.bz2
perlweeklychallenge-club-912a6af07557d35fa43ecf8b66a53c3eca58ddcc.zip
Week 209
-rw-r--r--challenge-209/zapwai/perl/ch-1.pl27
-rw-r--r--challenge-209/zapwai/perl/ch-2.pl49
2 files changed, 76 insertions, 0 deletions
diff --git a/challenge-209/zapwai/perl/ch-1.pl b/challenge-209/zapwai/perl/ch-1.pl
new file mode 100644
index 0000000000..014fee61ef
--- /dev/null
+++ b/challenge-209/zapwai/perl/ch-1.pl
@@ -0,0 +1,27 @@
+use v5.30.0;
+my @bits = (1, 0, 0);
+#my @bits = (1, 1, 1, 0);
+say "Input: \@bits = (".join(", ",@bits).")";
+my $out;
+do {
+ if (($bits[0] == 1) && ($bits[1] == 0)) {
+ $out .= 'b';
+ shift @bits;
+ shift @bits;
+ } elsif (($bits[0] == 1) && ($bits[1] == 1)) {
+ $out .= 'c';
+ shift @bits;
+ shift @bits;
+ } elsif ($bits[0] == 0) {
+ $out .= 'a';
+ shift @bits;
+ }
+} while ($#bits + 1);
+my @let = split("",$out);
+print "Output: ";
+if ($let[$#let] eq 'a') {
+ print "1";
+} else {
+ print "0";
+}
+say "\t(Decodes to $out)";
diff --git a/challenge-209/zapwai/perl/ch-2.pl b/challenge-209/zapwai/perl/ch-2.pl
new file mode 100644
index 0000000000..bfc7c5849c
--- /dev/null
+++ b/challenge-209/zapwai/perl/ch-2.pl
@@ -0,0 +1,49 @@
+use v5.30.0;
+no warnings;
+my @accounts = [ ["A", "a1\@a.com", "a2\@a.com"],
+ ["B", "b1\@b.com"],
+ ["A", "a3\@a.com", "a1\@a.com"] ];
+my @A = @{$accounts[0]};
+# Display Input
+say "Input:";
+for my $i (0 .. $#A) {
+ for my $j (0 .. $#{$A[$i]}) {
+ print $A[$i][$j]." ";
+ }
+ say ;
+}
+# Search rows for matching email data.
+for my $i (0 .. $#A - 1) {
+ for my $i2 ($i+1 .. $#A) {
+ next if ($A[$i][0] ne $A[$i2][0]);
+ foreach my $j (1 .. $#{$A[$i]}) {
+ foreach my $j2 (1 .. $#{$A[$i2]}) {
+ next if ($A[$i][$j] ne $A[$i2][$j2]);
+ #It's mergin' time!
+ #Push all of row i2 entries onto row i, then remove row i2.
+ foreach my $k (1 .. $#{$A[$i2]}) {
+ push @{$A[$i]}, $A[$i2][$k];
+ }
+ splice @A, $i2, 1;
+ }
+ }
+ }
+}
+# Remove duplicates
+for my $i (0 .. $#A) {
+ my @list;
+ for my $j (1 .. $#{$A[$i]}) {
+ next if ( $A[$i][$j] ~~ @list);
+ push @list, $A[$i][$j];
+ }
+ splice @{$A[$i]}, 1;
+ push @{$A[$i]}, @list;
+}
+# Display Output
+say "\nOutput:";
+for my $i (0 .. $#A) {
+ for my $j (0 .. $#{$A[$i]}) {
+ print $A[$i][$j]." ";
+ }
+ say "";
+}