Re: [Haskell-cafe] For Euler 25; What is the first term in the Fibonacci sequence to contain 1000 digits?; the following seems to work.

2011-05-19 Thread Sebastian Fischer
On Thu, May 19, 2011 at 7:29 PM, KC  wrote:

> For Euler 25; What is the first term in the Fibonacci sequence to
> contain 1000 digits?; the following seems to work.
>
>
> -- For number of digits being 5 or more.
> fibNdigits :: Int -> Int
> fibNdigits nDigits = floor (((fromIntegral nDigits) - 1.0) / (logBase
> 10 phi)) + 2
>  where
>sq5 = sqrt 5 :: Double
>phi = (1 + sq5) / 2
>


(length . show) is fast enough for me. The following gives the answer in a
fraction of a second.

# cabal install fibonacci
# ghci
ghci> import Data.Numbers.Fibonacci
ghci> head . filter ((==1000) . length . show) $ map fib [0..]
10700662663827589367649805844573968850836838966321516650132352033753145206046940406218891475824897926578046948881775919574843364666725699595129960304612627480924821861440694330512347744427502737817530875793916661921492591867595539664228371489431130746995034395470019854326097230672901928705264472437261177158218255484911205250132014786129659313817922355596574520395061375514678375432291196021299340482607061753977068470682028954869026661854351245219003694806413574474709117076197669456910700980243934396174741037369125032313655321647736970231677550515951735184605799549194109677783732296657965816465139034881542563101842241902598460880001101862024549393711365165703944762958471454852342595042858242530608354443542821261100899286379504800689433030977321783486454311320576565986845628861680871869383529735064398629764066723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] For Euler 25; What is the first term in the Fibonacci sequence to contain 1000 digits?; the following seems to work.

2011-05-19 Thread KC
For Euler 25; What is the first term in the Fibonacci sequence to
contain 1000 digits?; the following seems to work.


-- For number of digits being 5 or more.
fibNdigits :: Int -> Int
fibNdigits nDigits = floor (((fromIntegral nDigits) - 1.0) / (logBase
10 phi)) + 2
  where
sq5 = sqrt 5 :: Double
phi = (1 + sq5) / 2


-- 
--
Regards,
KC

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe