diff options
| -rw-r--r-- | challenge-324/bob-lied/perl/ch-1.pl | 14 |
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; } |
