Hi there, newbie here
solved Project Euler #4 problem with Julia and, althogh the timing is good, I got too many allocations (around 100k) for such a small program.
I’ve tried with explicit types in the variables and didn’t get any improvements, so obviously I’m doing something wrong.
Here is the code
> function ispalindrome(n) > for i in zip(digits(n), reverse!(digits(n))) > if i ≠ i[end] > return false > end > end > return true > end > > > function Problem4() > #= > A palindromic number reads the same both ways. The largest palindrome made > from the product of two 2-digit numbers is 9009 = 91 x 99. > > Find the largest palindrome made from the product of two 3-digit numbers. > =# > > ans = 10_001 > for i = 100:999, j = i:999 > if (i*j > ans) && ispalindrome(i*j) > ans = i*j > end > end > return ans > > end > > @btime Problem4() > println("Result: ", Problem4())