Skip to content

Commit

Permalink
Improved gen_fib() (Grame Hewson, GH #166).
Browse files Browse the repository at this point in the history
  • Loading branch information
chromatic committed Oct 23, 2011
1 parent e70412e commit 563d7ae
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,6 @@ E: btilly@gmail.com

N: Michael Lang
E: michi@jackal-net.at

N: Graeme Hewson
E: ghewson@wormhole.me.uk
4 changes: 2 additions & 2 deletions sections/closures.pod
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ elements you need:

sub gen_fib
{
my @fibs = (0, 1, 1);
my @fibs = (0, 1);

return sub
{
my $item = shift;

if ($item >= @fibs)
{
for my $calc ((@fibs - 1) .. $item)
for my $calc (@fibs .. $item)
{
$fibs[$calc] = $fibs[$calc - 2] + $fibs[$calc - 1];
}
Expand Down

0 comments on commit 563d7ae

Please sign in to comment.