-
Notifications
You must be signed in to change notification settings - Fork 0
/
0038.js
31 lines (24 loc) · 830 Bytes
/
0038.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
Project Euler problem 38
*/
import { verificaSeNumeroPandigital } from './0000.js';
function problema38() {
let maxPandigital = 0;
for (let n = 1; n < 10000; n++) {
let concatenatedProduct = '';
for (let i = 1; i <= 9; i++) {
concatenatedProduct += (n * i).toString();
// Se a string resultante for maior que 9 dígitos, pare o loop interno
if (concatenatedProduct.length > 9) {
break;
}
if (concatenatedProduct.length === 9 && verificaSeNumeroPandigital(concatenatedProduct)) {
// Se a string for pandigital, atualize o máximo encontrado
maxPandigital = Math.max(maxPandigital, parseInt(concatenatedProduct, 10));
}
}
}
console.log('Maior número pandigital:', maxPandigital);
}
// Chame a função para resolver o problema
problema38();