Project Euler

Problem #36

The decimal number, 585 = 1001001001_(2) (binary), is palindromic in both bases.

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

(Please note that the palindromic number, in either base, may not include leading zeros.)

Clojure: Running time = 5.29s
+;binary

+;is-palindrome?

(defn p36 []
  (println
    (apply + (filter #(and (is-palindrome? %) (is-palindrome? (binary %))) (range 1 1000000)))
  )
)

Erlang: Running time = 0.62s
+%binary

+%is_palindrome

p36()->
	p36(1,0).
p36(1000000,Sum)->io:format("~w~n",[Sum]);
p36(N,Sum)->
	case is_palindrome(N) of
		true->
			B=binary(N),
			case B==lists:reverse(B) of
				true->
					p36(N+1,Sum+N);
				false->
					p36(N+1,Sum)
			end;
		false->
			p36(N+1,Sum)
	end.

Ruby: Running time = 2.06s
+#Enumerable

+#isPalindrome?

def p36
  puts (1..1000000).select{|i|isPalindrome?(i) and isPalindrome?(i.to_s(2))}.sum
end