[Haskell-cafe] Fibbonachi numbers algorithm work TOO slow.
westondan at imageworks.com
Mon Nov 5 20:04:30 EST 2007
I assume you meant
> fib n=(((1+s)/2)^n-((1-s)/2)^n)/s where s=sqrt 5
Your solution starts to diverge from reality at n = 76:
> fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
Prelude> let n = 76 in fibs !! n - round (fib n)
jerzy.karczmarczuk at info.unicaen.fr wrote:
> Andrew Bromage:
>> G'day all.
>> (MIS)Quoting Dan Weston:
>>> fib00 = 0
>>> fib01 = 1
>>> fib02 = fib00 + fib01
>>> fib7698760 = fib7698759 + fib7698758
>> This is why we don't pay programmers by LOC.
>> Incidentally, we've been here before. Check out this thread:
> There is one solution missing there (unless I skipped it)
> fib n=((1+s)/2)^n-((1-s)/2)^n)/s where s=sqrt 5
> If some of you complain that this is real, not integer, please remember
> Leonardo of Pisa thought of applying this to rabbits. Well, rabbits are
> not integers, they eat carrots and have long ears. They are real thing.
> Well, sqrt is Floating.
> Now, floating rabbits are less common.
> Jerzy Karczmarczuk
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe