Problem 36

Below, one can find my solution to the 36th Euler problem:

    import Numeric
    import Char
    import List

    f i = isPalindrome (show i) && isPalindrome (showIntAtBase 2 intToDigit i "")
      where isPalindrome l = l == reverse l

    main = print $ sum [i | i <- [1..10^6], f i]

GHC’s execution time was good enough:

real 0m0.175s user 0m0.171s sys 0m0.003s

Published: May 30 2010

blog comments powered by Disqus