Monday, June 14, 2010

Problem 36: Find the sum of all numbers less than one million, which are palindromic in base 10 and base 2.

Reusing isPalindrome from Problem 4 and leveraging System.Convert for obtaining the binary representation of a given decimal number, this problem is trivial.

let problem36a =
    {1..999999}
    |> Seq.filter (fun n -> (isPalindrome (n|>string)) && (isPalindrome (System.Convert.ToString(n, 2))))
    |> Seq.sum

No comments:

Post a Comment