Sat, 27 Mar 2004
Counting Fibonacci numbers
I need to stop this silliness. Couldn’t sleep, so I got up early and played with perl and Fibonacci numbers some more.
The latest incarnation prints the n-th Fibonacci number where n is passed as an argument. Here, n is 1000:
perl -MMath::BigInt -e '$b=new Math::BigInt
1;($a,$b)=($b,$a+$b)while--$ARGV[0];print"$b\n"' 1000
That’s assuming Fibonacci numbers begin with one instead of zero. I’ve seen them described both ways. Is zero a Fibonacci number?
[/programming] [link]
About this weblog
This site is the personal weblog of Marc Mims. You can contact Marc
by sending e-mail to:
[email protected].
Marc writes here about cycling, programming, Linux, and other items of personal interest.
This site is syndicated with RSS.
Archives
Credits
CSS stolen from Tom Coates who didn't even complain.