function findDecompositionSomme(target) {
function find(start, history) {
if (start == target)
return history;
else if (start > target)
return null;
else
return find(start + 5, `(${history} + 5 )`) ||
find(start + 3, `(${history} + 3 )`) ||
find(start + 2, `(${history} + 2 )`);
}
return `${target} = ${find(1 , "1")}`
}
console.log(findDecompositionSomme(10));
function find(start, history) {
if (start == target)
return history;
else if (start > target)
return null;
else
return find(start + 5, `(${history} + 5 )`) ||
find(start + 3, `(${history} + 3 )`) ||
find(start + 2, `(${history} + 2 )`);
}
return `${target} = ${find(1 , "1")}`
}
console.log(findDecompositionSomme(10));
Vous pourrez modifier le code pour faire des décompositions somme produit !