Skip to content

Project Euler Problem 26

November 18, 2011

Project Euler Problem 26 requires familiarity with some math information that can be found at http://mathworld.wolfram.com/FullReptendPrime.html. Translating it into F# gives:

let isFullReptent n =
    if n % 2 = 0 || n % 5 = 0 then
        false // n is not relatively prime to 10
    else
        (Seq.initInfinite (fun x -> x+1)
        |> Seq.filter (fun x -> ((pown 10I x) - 1I) % (bigint (int n)) = 0I)
        |> Seq.head) + 1 = n // cycle length is n - 1

let problem026 () =
    [1..999]
    |> Seq.filter isFullReptent |> Seq.max
Advertisements

From → Project Euler

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: