This puzzle requires that we find the first Fibonacci number with 1000 digits.

Given what we have already created in problem 2 it is a fairly simple problem to solve. All we need to do is to introduce a new function that checks the digit count:

let hasYdigits x y =

    let upperLimit = BigInteger.Pow(10I,y-1)

    x >= upperLimit

 

let has1000digits (x : BigInteger) =  hasYdigits x 1000

Note that I'm being explicit about the type of the parameter because I want it to use BigIntegers.

Now the problem is solved by filtering out all elements in the infinite list that don't have 1000 digits and with the resulting sequence taking the first element (Seq.head) and then bailing out.

let euler25 = fibSet

                |> Seq.filter (fun x -> has1000digits x)

                |> Seq.head 

 

printfn "%A" euler25

Console.ReadLine() |> ignore

Bookmark and Share