From cae79bc6bb2ad3c7a59614a13d43e3bb25ebdcc8 Mon Sep 17 00:00:00 2001 From: Bob Lied Date: Tue, 3 Jun 2025 07:41:01 -0500 Subject: Task 1 alternative with natatime --- challenge-324/bob-lied/perl/ch-1.pl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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; } -- cgit