diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2023-11-07 15:56:47 -0500 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2023-11-07 15:56:47 -0500 |
| commit | bde5ad27ca059e708836cc2d0b4768a642530702 (patch) | |
| tree | e9e0a6cca561312567881642d9320118effdca8c | |
| parent | db4d9fe6bf77ff58c31ec3e9d2f71d8acf7d58d4 (diff) | |
| download | perlweeklychallenge-club-bde5ad27ca059e708836cc2d0b4768a642530702.tar.gz perlweeklychallenge-club-bde5ad27ca059e708836cc2d0b4768a642530702.tar.bz2 perlweeklychallenge-club-bde5ad27ca059e708836cc2d0b4768a642530702.zip | |
DAJ 242
| -rw-r--r-- | challenge-242/dave-jacoby/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-242/dave-jacoby/perl/ch-1.pl | 35 | ||||
| -rw-r--r-- | challenge-242/dave-jacoby/perl/ch-2.pl | 37 |
3 files changed, 73 insertions, 0 deletions
diff --git a/challenge-242/dave-jacoby/blog.txt b/challenge-242/dave-jacoby/blog.txt new file mode 100644 index 0000000000..303a9224a3 --- /dev/null +++ b/challenge-242/dave-jacoby/blog.txt @@ -0,0 +1 @@ +https://jacoby.github.io/2023/11/07/like-the-deserts-miss-the-rain-weekly-challenge-242.html diff --git a/challenge-242/dave-jacoby/perl/ch-1.pl b/challenge-242/dave-jacoby/perl/ch-1.pl new file mode 100644 index 0000000000..fbdeaec80a --- /dev/null +++ b/challenge-242/dave-jacoby/perl/ch-1.pl @@ -0,0 +1,35 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ say postderef signatures state }; + +use List::Compare; + +my @examples = ( + + [ [ 1, 2, 3 ], [ 2, 4, 6 ], ], + [ [ 1, 2, 3, 3 ], + [ 1, 1, 2, 2 ], ], + +); +for my $e (@examples) { + my @output = missing_members( $e->@* ); + my $arr1 = join ', ', $e->[0]->@*; + my $arr2 = join ', ', $e->[1]->@*; + my $output = join ', ', + map { qq{[$_]} } map { join ', ', $_->@* } @output; + say <<~"END"; + Input: \@arr1 = ($arr1) + \@arr2 = ($arr2) + Output: ($output) + END +} + +sub missing_members (@input) { + my $lc = List::Compare->new(@input); + my @first = $lc->get_unique; + my @last = $lc->get_complement; + my @output = grep { scalar $_->@* } ( \@first, \@last ); + return @output; +} diff --git a/challenge-242/dave-jacoby/perl/ch-2.pl b/challenge-242/dave-jacoby/perl/ch-2.pl new file mode 100644 index 0000000000..f369ca8f50 --- /dev/null +++ b/challenge-242/dave-jacoby/perl/ch-2.pl @@ -0,0 +1,37 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ say postderef signatures state }; + +my @examples = ( + + [ [ 1, 1, 0 ], [ 1, 0, 1 ], [ 0, 0, 0 ] ], + [ [ 1, 1, 0, 0 ], [ 1, 0, 0, 1 ], [ 0, 1, 1, 1 ], [ 1, 0, 1, 0 ] ], +); + +for my $e (@examples) { + my @output = flip_matrix($e); + my $input = join ', ', map { qq{[$_]} } map { join ', ', $_->@* } $e->@*; + my $output = join ', ', + map { qq{[$_]} } map { join ', ', $_->@* } @output; + say <<~"END"; + Input: \@matrix = ($input) + Output: ($output) + END +} + +sub flip_matrix ($matrix) { + my $new_matrix; + for my $row ( 0 .. -1 + scalar $matrix->@* ) { + $new_matrix->[$row]->@* = + map { ( $_ + 1 ) % 2 } reverse $matrix->[$row]->@*; + } + # display_matrix($matrix); + # display_matrix($new_matrix); + return $new_matrix->@*; +} + +sub display_matrix ($matrix) { + say join "\n", '', map { join ' ', $_->@* } $matrix->@*; +} |
