aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Lied <boblied+github@gmail.com>2025-06-03 07:41:01 -0500
committerBob Lied <boblied+github@gmail.com>2025-06-03 07:41:01 -0500
commitcae79bc6bb2ad3c7a59614a13d43e3bb25ebdcc8 (patch)
tree0b7cdcbcaa4baac28327dff498b815988bc10584
parent9e46bf73c63502794ff5ef65ea0b8c115500484f (diff)
downloadperlweeklychallenge-club-cae79bc6bb2ad3c7a59614a13d43e3bb25ebdcc8.tar.gz
perlweeklychallenge-club-cae79bc6bb2ad3c7a59614a13d43e3bb25ebdcc8.tar.bz2
perlweeklychallenge-club-cae79bc6bb2ad3c7a59614a13d43e3bb25ebdcc8.zip
Task 1 alternative with natatime
-rw-r--r--challenge-324/bob-lied/perl/ch-1.pl14
1 files changed, 14 insertions, 0 deletions
diff --git a/challenge-324/bob-lied/perl/ch-1.pl b/challenge-324/bob-lied/perl/ch-1.pl
index 00e0ba6ad8..4e4d89cae9 100644
--- a/challenge-324/bob-lied/perl/ch-1.pl
+++ b/challenge-324/bob-lied/perl/ch-1.pl
@@ -72,6 +72,16 @@ sub makeArray($r, $c, @ints)
return \@array;
}
+sub ma2($r, $c, @ints)
+{
+ use List::MoreUtils qw/natatime/;
+ my @array;
+ my @row;
+ my $iterator = natatime $c, @ints;
+ push @array, [ @row ] while ( @row = $iterator->() );
+ return \@array;
+}
+
sub runTest
{
use Test2::V0;
@@ -82,5 +92,9 @@ sub runTest
like( dies { makeArray(7,3, 2,4,6) }, qr/Size error/, "Wrong dimensions");
+ is( ma2(2,2, 1,2,3,4), [[1,2],[3,4] ], "Example 1");
+ is( ma2(1,3, 1,2,3 ), [[1,2,3] ], "Example 2");
+ is( ma2(4,1, 1,2,3,4), [[1],[2],[3],[4]], "Example 3");
+
done_testing;
}