q(May all your Christmases be white.) =~ s/Christmase/loop/r =~ s/white/implicit/r
####
#!/usr/bin/perl
use strict; # https://theweeklychallenge.org/blog/perl-weekly-challenge-248/#TASK2
use warnings;
use List::AllUtils qw( zip_by reduce );
use Data::Dump qw( pp );
sub slide
{
my @new;
reduce { push @new, $a + $b; $b } @_;
@new;
}
for ( [ [1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12] ],
[ [1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1] ],
)
{
print 'Input: $a = ', pp($_), "\n";
my @new = zip_by { [ @_ ] } map [ slide @$_ ],
zip_by { [ @_ ] } map [ slide @$_ ], @$_;
print 'Output: $b = ', pp(\@new), "\n\n";
}
##
##
Input: $a = [[1 .. 4], [5 .. 8], [9 .. 12]]
Output: $b = [[14, 18, 22], [30, 34, 38]]
Input: $a = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
Output: $b = [[2, 1, 0], [1, 2, 1], [0, 1, 2]]