Skip to content

Project Euler Problem 55

December 4, 2011

Project Euler Problem 55 solution:

open System

let isPalindromic (n: bigint) =
    let isPalindrom (s: string) =
        String(s.ToCharArray() |> Array.rev) = s
    isPalindrom (string n)

let revert (n: bigint) =
    bigint.Parse(String((string n).ToCharArray() |> Array.rev))

let isLychrel (n: bigint) =
    Seq.unfold (fun (i,x) ->
        if isPalindromic x || i > 49 then None
        else Some((i,x), (i+1, x + (revert x))))
        (1, n + (revert n))
    |> Seq.length |> fun x -> if x >= 49 then 1 else 0

let problem055 () =
    [1I..9999I]
    |> Seq.map isLychrel
    |> Seq.sum
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: