Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Fibonacci Generator

by PERLscienceman (Curate)
on Jul 06, 2003 at 04:27 UTC ( [id://271725]=note: print w/replies, xml ) Need Help??


in reply to Fibonacci Generator

I was going through the "miscellaneous nodes" section and found this one of many to be interesting. So... I thought I would do a little digging and sure enough, consistent with one of the many glories of Perl (there is a module for just about everything), I found one, on CPAN, that generates Fibonacci numbers and related things.
This is the CPAN documentation URL:
http://search.cpan.org/author/VIPUL/Math-Fibonacci-1.5/lib/Math/Fibonacci.pm
And here is a little chunk of code, (all of 5 lines), which generates a 10 number Fibonacci Series:
#!/usr/bin/perl -w use strict; use Math::Fibonacci qw(series); my @fibonacci=series(10); print "@fibonacci\n";

The wonders of Perl!

Replies are listed 'Best First'.
Re^2: Fibonacci Generator
by Anonymous Monk on May 26, 2007 at 10:02 UTC
    could try this out - if (n==1 || n == 2) { return 1;} else { return (fib(n-1) + fib(n-2)); }
      could try this out - if (n==1 || n == 2) { return 1;} else { return (fib(n-1) + fib(n-2)); }

      Whoa! What algorithm is that? It must be something absolutely new and ingenious: has anybody seen anything similar before?!? But... what language is that?

Re^2: Fibonacci Generator
by Anonymous Monk on Dec 06, 2009 at 03:48 UTC
    i think this is much better:--- #!/user/bin/perl $a=0; $b=1; for($i=0;$i<=20;$i++) { print "$a\n"; $c=$a+$b; $a=$b; $b=$c; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://271725]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-03-29 06:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found