aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels van Dijke <perlboy@cpan.org>2021-04-15 08:30:01 +0000
committerNiels van Dijke <perlboy@cpan.org>2021-04-15 08:30:01 +0000
commitdbb4d44017925091fa42623f9081b5cbf47027cc (patch)
treefafe83917c4593fd32b7847781b20e8cb6f0e1b7
parentf33dee7758eb47f54150aaa4c608ce1e61a7302c (diff)
downloadperlweeklychallenge-club-dbb4d44017925091fa42623f9081b5cbf47027cc.tar.gz
perlweeklychallenge-club-dbb4d44017925091fa42623f9081b5cbf47027cc.tar.bz2
perlweeklychallenge-club-dbb4d44017925091fa42623f9081b5cbf47027cc.zip
Corrected the scipt ch-2.pl after rereading the Wikipedia page.
-rwxr-xr-xchallenge-108/perlboy1967/perl/ch-2.pl11
1 files changed, 4 insertions, 7 deletions
diff --git a/challenge-108/perlboy1967/perl/ch-2.pl b/challenge-108/perlboy1967/perl/ch-2.pl
index 750364b8c0..3ded2c8eb9 100755
--- a/challenge-108/perlboy1967/perl/ch-2.pl
+++ b/challenge-108/perlboy1967/perl/ch-2.pl
@@ -11,14 +11,14 @@ use v5.16;
use strict;
use warnings;
-my @bn = (1);
+my @bn = 1;
# Using the 'Bell triangle' algorithm
my $bnT = [[1]];
-my $bTRidx = 1;
-while (scalar(@bn) < 10) {
+foreach my $bTRidx (1..10) {
+
my $prevTRdim = scalar(@{$bnT->[$bTRidx-1]});
# Copy
@@ -29,11 +29,8 @@ while (scalar(@bn) < 10) {
$bnT->[$bTRidx][$bTCidx] =
$bnT->[$bTRidx-1][$bTCidx-1] +
$bnT->[$bTRidx][$bTCidx-1];
-
- push(@bn, $bnT->[$bTRidx][$bTCidx]);
- last if (scalar(@bn) >= 10);
}
- $bTRidx++;
+ push(@bn, $bnT->[$bTRidx][-1]);
}
# Print