first commit with existing project files

This commit is contained in:
Vincent Guillet
2025-04-02 11:33:15 +02:00
parent f447ea8a0f
commit c8e200b42f
18 changed files with 515 additions and 0 deletions

28
algo_js/spirale.js Normal file
View File

@@ -0,0 +1,28 @@
const prompt = require('prompt-sync')();
let listePremiers = tablePremiers(parseInt(prompt("Quantité de nombres premiers : ")));
for (let i = 0; i < listePremiers.length; i++) {
console.log(listePremiers[i]);
}
function tablePremiers(n) {
let table = [];
let i = 2; // Le premier nombre premier
for (let j = 0; j < n; j++) {
while (!isPremier(i)) i++;
table.push(i);
i++;
}
return table;
}
function isPremier(n) {
if (n <= 1) return false;
for (let i = 2; i <= Math.sqrt(n); i++) {
if (n % i === 0) return false;
}
return true;
}