aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-003/joelle-maslak/perl5/ch-2.pl35
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-003/joelle-maslak/perl5/ch-2.pl b/challenge-003/joelle-maslak/perl5/ch-2.pl
new file mode 100755
index 0000000000..bdc3cd8c51
--- /dev/null
+++ b/challenge-003/joelle-maslak/perl5/ch-2.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+
+use v5.26;
+use strict;
+use warnings;
+
+# Turn on method signatures
+use feature 'signatures';
+no warnings 'experimental::signatures';
+
+if ( !@ARGV ) { die("Provide number of rows") }
+if ( $ARGV[0] < 3 ) { die("Must provide at least 3 rows") }
+if ( int( $ARGV[0] ) != $ARGV[0] ) { die("Must provide an integer") }
+
+my $rowcount = $ARGV[0];
+
+my @rows;
+
+for ( my $i = 0; $i < $rowcount; $i++ ) {
+ my @row;
+ if ( !$i ) {
+ @row = 1;
+ } else {
+ push @row, 1;
+ for ( my $j = 1; $j < $i; $j++ ) {
+ push @row, $rows[ $i - 1 ]->[ $j - 1 ] + $rows[ $i - 1 ]->[$j];
+ }
+ push @row, 1;
+ }
+ push @rows, \@row;
+
+ for ( my $j = 1; $j < $rowcount - $i; $j++ ) { print(" ") }
+ say join( " ", map { sprintf( "%3d", $_ ) } @{ $rows[$i] } );
+}
+