aboutsummaryrefslogtreecommitdiff
path: root/challenge-003
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-01-28 14:01:34 +0100
committerAbigail <abigail@abigail.be>2021-01-28 14:01:34 +0100
commit677cf089ed01cde533368b8dffcc244c8e38670f (patch)
tree2f13d1a568964ddf7902828c13c4a83cf882f360 /challenge-003
parent7d2dd894b51a42703190653da355cd952ada800c (diff)
downloadperlweeklychallenge-club-677cf089ed01cde533368b8dffcc244c8e38670f.tar.gz
perlweeklychallenge-club-677cf089ed01cde533368b8dffcc244c8e38670f.tar.bz2
perlweeklychallenge-club-677cf089ed01cde533368b8dffcc244c8e38670f.zip
Don't assume a single input.
So, the Perl solution is more inline with the others.
Diffstat (limited to 'challenge-003')
-rw-r--r--challenge-003/abigail/perl/ch-2.pl44
1 files changed, 23 insertions, 21 deletions
diff --git a/challenge-003/abigail/perl/ch-2.pl b/challenge-003/abigail/perl/ch-2.pl
index a6af9168d0..d5c14c4701 100644
--- a/challenge-003/abigail/perl/ch-2.pl
+++ b/challenge-003/abigail/perl/ch-2.pl
@@ -17,28 +17,30 @@ use experimental 'lexical_subs';
# Run as: perl ch-2.pl < input-file
#
-chomp (my $rows = <>);
-
-#
-# 0-th row
-#
-my @row = (1);
-say "@row";
-
-foreach (1 .. $rows) {
- #
- # Calculate the next row from the current row
- #
- my @new = map {($_ == 0 ? 0 : $row [$_ - 1]) +
- ($_ == @row ? 0 : $row [$_])} 0 .. @row;
-
- #
- # Print
- #
- say "@new";
+while (my $rows = <>) {
+ chomp $rows;
#
- # New row becomes current row
+ # 0-th row
#
- @row = @new;
+ my @row = (1);
+ say "@row";
+
+ foreach (1 .. $rows) {
+ #
+ # Calculate the next row from the current row
+ #
+ my @new = map {($_ == 0 ? 0 : $row [$_ - 1]) +
+ ($_ == @row ? 0 : $row [$_])} 0 .. @row;
+
+ #
+ # Print
+ #
+ say "@new";
+
+ #
+ # New row becomes current row
+ #
+ @row = @new;
+ }
}