diff options
| author | Niels van Dijke <perlboy@cpan.org> | 2021-04-15 08:30:01 +0000 |
|---|---|---|
| committer | Niels van Dijke <perlboy@cpan.org> | 2021-04-15 08:30:01 +0000 |
| commit | dbb4d44017925091fa42623f9081b5cbf47027cc (patch) | |
| tree | fafe83917c4593fd32b7847781b20e8cb6f0e1b7 | |
| parent | f33dee7758eb47f54150aaa4c608ce1e61a7302c (diff) | |
| download | perlweeklychallenge-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-x | challenge-108/perlboy1967/perl/ch-2.pl | 11 |
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 |
