
Largest Palindrome Product
A palindromic number reads the same both ways. The largest palindrome made from the product of two $2$-digit numbers is $9009 = 91 \times 99$.
Find the largest palindrome made from the product of two $3$-digit numbers.
A palindromic number reads the same both ways. The largest palindrome made from the product of two $2$-digit numbers is $9009 = 91 \times 99$.
Find the largest palindrome made from the product of two $3$-digit numbers.
Qui basta convertire la richiesta in sintassi di Julia: ci interessa il più alto numero palindromo ottenuto come il prodotto di due numeri e da tre cifre? facciamo un loop con e sul range dei numeri da 3 cifre, e controlliamo se il loro prodotto è palindromo e se è maggiore del candidato trovato finora (perché ci interessa trovare il massimo numero che ha questa caratteristica). Il controllo sulla palindromia lo si fa confrontando la stringa del numero con sè stessa invertita (tipo 121 è uguale a 121, mentre 123 è diverso da 321).
max_n = 1 # n=i*j
max_i = 1; max_j = 1
for i in 100:998
for j in (i+1):999
n = i*j
if string(n) == reverse(string(n)) && n>max_n
max_n = n
max_i = i; max_j = j
end
end
end
@show max_n, max_i, max_j