How about a more efficient search strategy? for x from 999 to 121: // 121*121 is palindrome, don't go lower that that for y from 999 to x: // only search upper triangle of this matrix z=x*y if z > maxPalindromeNumSoFar: // only check palindrome-ism if z is bigger check z for palindrome-ism and replace if bigger And add a bit of domain knowledge. 444,444 = 481*924, so further constrain the search range: for x from 999 to 481: for y from 999 to max(x, 444444/x): There's also a bit of number theory about palindromic numbers have factors of 11 or 101, not sure how best to integrate that info...