The decimal number, 585 = 10010010012 (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.)
;binary ;is-palindrome? (defn p36 [] (println (apply + (filter #(and (is-palindrome? %) (is-palindrome? (binary %))) (range 1 1000000))) ) )
%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.
#Enumerable #isPalindrome? def p36 puts (1..1000000).select{|i|isPalindrome?(i) and isPalindrome?(i.to_s(2))}.sum end