G'day all.
Quoting Mathew Mills <[EMAIL PROTECTED]>:
> I guess I don't get any points for an approximate solution, ay?
If only there was an iterative algorithm. Then you could use your
method to get a great initial estimate...
Cheers,
Andrew Bromage
Doug Quale <[EMAIL PROTECTED]> writes:
> Mathew Mills <[EMAIL PROTECTED]> writes:
>
> > Is there anything that can be done (easily) to reduce the rounding errors?
>
> The hint that I gave before is one easy way.
>
> > fib :: Integer -> Integer
> > fib x = let phi = ( 1 + sqrt 5 ) / 2
> >
On 2006-06-15 at 17:33BST "Vladimir Portnykh" wrote:
> Fibonacci numbers implementations in Haskell one of the classical examples.
> An example I found is the following:
>
> fibs :: [Int]
> fibs = 0 : 1 : [ a + b | (a, b) <- zip fibs (tail fibs)]
>
> Can we do better?
Well, you've had various v
Mathew Mills <[EMAIL PROTECTED]> writes:
> Is there anything that can be done (easily) to reduce the rounding errors?
The hint that I gave before is one easy way.
> fib :: Integer -> Integer
> fib x = let phi = ( 1 + sqrt 5 ) / 2
> in truncate( ( 1 / sqrt 5 ) * ( phi ^ x + 0.5) )
You r
Chris Kuklewicz wrote:
Mathew Mills wrote:
I guess I don't get any points for an approximate solution, ay?
Is there anything that can be done (easily) to reduce the rounding
errors?
http://www.google.com/search?q=haskell+exact+real+arithmetic
Using Era.hs (with the patch at
http://www.
Mathew Mills wrote:
I guess I don't get any points for an approximate solution, ay?
Is there anything that can be done (easily) to reduce the rounding errors?
http://www.google.com/search?q=haskell+exact+real+arithmetic
___
Haskell-Cafe mailing lis
I guess I don't get any points for an approximate solution, ay?
Is there anything that can be done (easily) to reduce the rounding errors?
On 6/15/06 11:23 PM, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> G'day all.
>
> Quoting Mathew Mills <[EMAIL PROTECTED]>:
>
>> How about the closed f
Spencer Janssen writes (in the Haskell Cafe):
Here's some code I wrote a while back for computing the nth Fibonacci
number. It has O(log n) time complexity [..]
The nth Fibonacci number has O(n) digits.
Cheers,
Ronny Wichers Schreur
___
Haskell-C
G'day all.
Quoting Mathew Mills <[EMAIL PROTECTED]>:
> How about the closed form ;)
>
> > -- fib x returns the x'th number in the fib sequence
>
> > fib :: Integer -> Integer
>
> > fib x = let phi = ( 1 + sqrt 5 ) / 2
>
> > in truncate( ( 1 / sqrt 5 ) * ( phi ^ x - phi' ^ x ) )
>
>
> Seem
Mathew Mills <[EMAIL PROTECTED]> writes:
> -- fib x returns the x'th number in the fib sequence
> fib :: Integer -> Integer
> fib x = let phi = ( 1 + sqrt 5 ) / 2
> phi' = ( 1 - sqrt 5 ) / 2
> in truncate( ( 1 / sqrt 5 ) * ( phi ^ x - phi' ^ x ) )
>
> -- Seems pretty quick to m
How about the closed form ;)
> -- fib x returns the x'th number in the fib sequence
> fib :: Integer -> Integer
> fib x = let phi = ( 1 + sqrt 5 ) / 2
> in truncate( ( 1 / sqrt 5 ) * ( phi ^ x - phi' ^ x ) )
Seems pretty quick to me, even with sqrt and arbitrarily large numbers.
On
G'day all.
Quoting Vladimir Portnykh <[EMAIL PROTECTED]>:
> I wrote my own Fibonacci numbers generator:
>
> fib :: Int -> [Int]
> fib 0 = [0,0]
> fib 1 = [1,0]
> fib n = [sum prevFib, head prevFib] where a = fib (n - 1)
>
> To get the k-th number you do the following:
>
> result = head (fib k)
[
On Thu, 15 Jun 2006, Vladimir Portnykh wrote:
Fibonacci numbers implementations in Haskell one of the classical examples.
An example I found is the following:
fibs :: [Int]
fibs = 0 : 1 : [ a + b | (a, b) <- zip fibs (tail fibs)]
To get the k-th number you do the following:
Result = fibs !!
Here's some code I wrote a while back for computing the nth Fibonacci
number. It has O(log n) time complexity rather than O(n). It isn't
the most elegant example, but it should be one of the fastest
approaches.
import Data.Bits (shiftR, xor, (.|.), (.&.))
import Data.Word (Word32)
fibo :: W
Fibonacci numbers implementations in Haskell one of the classical examples.
An example I found is the following:
fibs :: [Int]
fibs = 0 : 1 : [ a + b | (a, b) <- zip fibs (tail fibs)]
To get the k-th number you do the following:
Result = fibs !! k
It is elegant but creates a list of all Fibona
15 matches
Mail list logo