# Project Euler Problem 65

Project Euler Problem 65 solution is a breeze. Reading thru this reveals that “the numerator of the third convergent is formed by multiplying the numerator of the second convergent by the third quotient, and adding the numerator of the first convergent”, or symbolically **n(i+1) = f(i+1) * n(i) + n(i-1)**, where **n(i)** is numerator of i-th convergent and **f(i)** is i-th member of continued fraction.

Translating above into the code yields:

let problem065 () = Seq.initInfinite (fun x -> seq [1I; 2I*(bigint x); 1I]) |> (Seq.skip 1 >> Seq.collect id >> Seq.skip 1) |> Seq.scan (fun (``n(i)``, ``n(i-1)``) i -> (i * ``n(i)`` + ``n(i-1)``, ``n(i)``)) (3I, 2I) |> (Seq.skip 98 >> Seq.head >> fst >> string >> Seq.map (string >> int) >> Seq.sum)

Advertisements

## Trackbacks & Pingbacks