diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-03-26 10:58:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-26 10:58:08 +0100 |
| commit | 06fa96309a44869a97c7ff851bbce30508b0b0a8 (patch) | |
| tree | 200a78f243a9bceb13dd1f639084b41dedd5f30c | |
| parent | 89c476125d7b15c6d714e61d9103c96d92af3e94 (diff) | |
| parent | 912a6af07557d35fa43ecf8b66a53c3eca58ddcc (diff) | |
| download | perlweeklychallenge-club-06fa96309a44869a97c7ff851bbce30508b0b0a8.tar.gz perlweeklychallenge-club-06fa96309a44869a97c7ff851bbce30508b0b0a8.tar.bz2 perlweeklychallenge-club-06fa96309a44869a97c7ff851bbce30508b0b0a8.zip | |
Merge pull request #7785 from zapwai/branch-for-209
Week 209
| -rw-r--r-- | challenge-209/zapwai/perl/ch-1.pl | 27 | ||||
| -rw-r--r-- | challenge-209/zapwai/perl/ch-2.pl | 49 |
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 ""; +} |
