diff options
| -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 |
