Brute force seems right for this problem.   You could write your solution as

  >./ (#~ (-: |.)@("."0@":)"0) , */~ 100+i. 900

Henry Rich

On 6/8/2014 10:46 AM, Jon Hough wrote:
I am pretty pleased that I completed Project Euler Q4.
Question:


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.


https://projecteuler.net/problem=4


My solution:

base =. "."0 ":

NB. Tests if y value is palindrome.
is_palindrome =. (# =)@:(=|.)@:base
NB. multiply all 3 digit nums (100 ~ 999)
mult =: (* is_palindrome"0) @ (*/)
NB. Create list of 3 digit nums.
list =. 100+ i.900

(>./)@:, list mult list
Although I'm glad got the answer, I'm wondering if it could be made terser, or 
if there is a much terser way to solve it? I went for a brute force approach.
For comparison here is a Haskell answer I found:
maximum[a*b|a<-[100..999],b<-[a..999],reverse(show(a*b))==show(a*b)]
Regards.                                        
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to