Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Fibonacci Numbers

by tmoertel (Chaplain)
on Feb 11, 2005 at 02:21 UTC ( [id://429967]=note: print w/replies, xml ) Need Help??


in reply to Fibonacci Numbers

Cool one liners for the Fibonacci series? Sure, there are bunches of them. Here's one that I wrote during an email exchange on the subject in which I was dared to "do something with bitwise ops":
perl -le'map{$_=$b.$a|"~",$b=$a,$a=$_,print}1..pop' 10
It doesn't just compute the series but also graphs it.

In the same exchange, the author of the dare (who shall remain nameless) also made the wisecrack that "recursion is for wimps." That compelled me to trot out the old Haskell classic:

fibs@(_:x) = 1 : 1 : zipWith (+) fibs x
That's it. The whole infinite series. Want the first 50 elements?
Fib> take 50 fibs [1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10 +946,17711,28657,46368,75025,121393,196418,317811,514229,832040,134626 +9,2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986 +,102334155,165580141,267914296,433494437,701408733,1134903170,1836311 +903,2971215073,4807526976,7778742049,12586269025]

Fun stuff.

Cheers,
Tom

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-16 18:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found