2021-06-15 00:49:18 -07:00
---
id: 5900f3701000cf542c50fe83
2021-07-30 01:41:44 +09:00
title: 'Problema 4: Prodotto palindromo più grande'
2021-06-15 00:49:18 -07:00
challengeType: 5
forumTopicId: 302065
dashedName: problem-4-largest-palindrome-product
---
# --description--
2021-07-30 01:41:44 +09:00
Un numero palindromico rimane lo stesso se viene letto in entrambi i sensi. Il palindromo più grande ottenuto dal prodotto con due numeri a due cifre è 9009 = 91 × 99.
2021-06-15 00:49:18 -07:00
2021-07-30 01:41:44 +09:00
Trova il più grande palindromo formato dal prodotto di due numeri con `n` cifre.
2021-06-15 00:49:18 -07:00
# --hints--
2021-07-30 01:41:44 +09:00
`largestPalindromeProduct(2)` dovrebbe restituire un numero.
2021-06-15 00:49:18 -07:00
```js
assert(typeof largestPalindromeProduct(2) === 'number');
```
2021-07-30 01:41:44 +09:00
`largestPalindromeProduct(2)` dovrebbe restituire 9009.
2021-06-15 00:49:18 -07:00
```js
assert.strictEqual(largestPalindromeProduct(2), 9009);
```
2021-07-30 01:41:44 +09:00
`largestPalindromeProduct(3)` dovrebbe restituire 906609.
2021-06-15 00:49:18 -07:00
```js
assert.strictEqual(largestPalindromeProduct(3), 906609);
```
# --seed--
## --seed-contents--
```js
function largestPalindromeProduct(n) {
return true;
}
largestPalindromeProduct(3);
```
# --solutions--
```js
const largestPalindromeProduct = (digit)=>{
let start = 1;
let end = Number(`1e${digit}` ) - 1;
let palindrome = [];
for(let i=start;i< =end;i++){
for(let j=start;j< =end;j++){
let product = i*j;
let palindromeRegex = /\b(\d)(\d?)(\d?).?\3\2\1\b/gi;
palindromeRegex.test(product) & & palindrome.push(product);
}
}
return Math.max(...palindrome);
}
```