A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.
Find the largest palindrome made from the product of two 3-digit numbers.
;cartesian-product ;is-palindrome? (defn p4 [] (println (apply max (filter is-palindrome? (map (fn [[a b]] (* a b)) (cartesian-product (range 100 1000) (range 100 1000))))) ) )
%is_palindrome p4()-> Candidates=lists:append(lists:map(fun(Top)-> lists:map(fun(T)->T*Top end, lists:seq(100,Top-1)) end,lists:seq(101,999))), Ans=lists:last(lists:sort(lists:filter(fun(X)->is_palindrome(X) end,Candidates))), io:format("~w~n",[Ans]).
#cartesian_product #isPalindrome? def p4 puts cartesian_product((100...1000),(100...1000)).map{|p|p[0]*p[1]}.select{|i|isPalindrome? i}.sort[-1] end
//isPalindrome def p4{ var l=0 for(i <- (100 until 1000); j<- (100 until 1000) if isPalindrome(i*j))if(i*j>l)l=i*j println(l) }