Skip to content

Project Euler Problem 36

November 22, 2011

Project Euler Problem 36 solution is succinct; function isPalindromic checks that base 2 and base 10 presentations of a number n are both palindromes:

open System

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

let isPalindromic (n: int) =
    isPalindrom (Convert.ToString (n, 2)) && isPalindrom (string n)

let problem036 () =
    {1..999999}
    |> Seq.filter isPalindromic |> 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: