![]() |
|
"be consistent" | |
PerlMonks |
Re^2: fibonacci numbers using subroutine?by moritz (Cardinal) |
on Aug 20, 2010 at 08:37 UTC ( #856208=note: print w/replies, xml ) | Need Help?? |
Just to show off, here's a Perl 6 solution:
Which you call as
To obtain the 8th fibonacci number. As an explanation, MAIN takes its arguments from the command line, and is run automatically at startup. as Int converts the command line argument (which is a string) to an integer (this is not sctrictly necessary). 0, 1, *+* ... * is a lazy, infinite list starting with 0 and 1, and then is built by summing the two previous elements. [$limit] takes the $limit's element of that list, with a zero-based index. (Which is why the fibonacci sequence starts with 0, 1 instead of 1, 1 in that program).
Perl 6 - links to (nearly) everything that is Perl 6.
In Section
Seekers of Perl Wisdom
|
|