first commit with existing project files
This commit is contained in:
12
algo_js/cafe.js
Executable file
12
algo_js/cafe.js
Executable file
@@ -0,0 +1,12 @@
|
||||
const prompt = require('prompt-sync')();
|
||||
|
||||
// Café ?
|
||||
|
||||
let reponse;
|
||||
|
||||
while (reponse != 'o' && reponse != 'n') {
|
||||
reponse = prompt("Café?");
|
||||
}
|
||||
|
||||
if (reponse == 'o') console.log("Voila votre café");
|
||||
else console.log("au revoir");
|
||||
52
algo_js/chiffre_cesar.js
Normal file
52
algo_js/chiffre_cesar.js
Normal file
@@ -0,0 +1,52 @@
|
||||
const prompt = require('prompt-sync')();
|
||||
|
||||
// Chiffre de César
|
||||
|
||||
let alphabetArray = [];
|
||||
alphabetToArray("abcdefghijklmnopqrstuvwxyz");
|
||||
|
||||
let message = prompt("Entrez un message à chiffrer : ");
|
||||
let messageChiffre = cesarEncrypt(message, 13);
|
||||
|
||||
console.log("Message chiffré : " + messageChiffre);
|
||||
console.log("Message déchiffré : " + cesarDecrypt(messageChiffre, 13));
|
||||
|
||||
function cesarEncrypt(message, decalage) {
|
||||
|
||||
let messageChiffre = "";
|
||||
|
||||
for (let i = 0; i < message.length; i++) {
|
||||
let lettre = message[i];
|
||||
let index = alphabetArray.indexOf(lettre);
|
||||
|
||||
if (index === -1) messageChiffre += lettre;
|
||||
else {
|
||||
let indexChiffre = (index + decalage) % alphabetArray.length;
|
||||
messageChiffre += alphabetArray[indexChiffre];
|
||||
}
|
||||
}
|
||||
return messageChiffre;
|
||||
}
|
||||
|
||||
function cesarDecrypt(message, decalage) {
|
||||
|
||||
let messageDechiffre = "";
|
||||
|
||||
for (let i = 0; i < message.length; i++) {
|
||||
let lettre = message[i];
|
||||
let index = alphabetArray.indexOf(lettre);
|
||||
|
||||
if (index === -1) messageDechiffre += lettre;
|
||||
else {
|
||||
let indexChiffre = (index - decalage + alphabetArray.length) % alphabetArray.length;
|
||||
messageDechiffre += alphabetArray[indexChiffre];
|
||||
}
|
||||
}
|
||||
return messageDechiffre;
|
||||
}
|
||||
|
||||
function alphabetToArray(alphabet) {
|
||||
for (let i = 1; i < alphabet.length; i++) {
|
||||
alphabetArray.push(alphabet[i]);
|
||||
}
|
||||
}
|
||||
19
algo_js/escaliers.js
Normal file
19
algo_js/escaliers.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const prompt = require('prompt-sync')();
|
||||
|
||||
// Escalier
|
||||
|
||||
const hash = "#"
|
||||
const space = " "
|
||||
|
||||
let nombre = prompt("Entrez le nombre de marches : ")
|
||||
|
||||
for (let i = 1; i <= nombre; i++) {
|
||||
let escalier = ""
|
||||
|
||||
for (let j = 1; j <= nombre; j++) {
|
||||
if (j <= nombre - i) escalier += space
|
||||
else escalier += hash
|
||||
}
|
||||
|
||||
console.log(escalier)
|
||||
}
|
||||
12
algo_js/multiplication.js
Normal file
12
algo_js/multiplication.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const prompt = require('prompt-sync')();
|
||||
|
||||
// Table de multiplication
|
||||
|
||||
let n = parseInt(prompt("Entrez un nombre entier : "));
|
||||
let table = "";
|
||||
|
||||
for (let i = 1; i <= 9; i++) {
|
||||
table += `${n} x ${i} = ${n * i}\n`;
|
||||
}
|
||||
|
||||
console.log(table);
|
||||
17
algo_js/nombre_cache.js
Normal file
17
algo_js/nombre_cache.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const prompt = require('prompt-sync')();
|
||||
|
||||
// Deviner le nombre caché
|
||||
|
||||
let nombreCache = Math.floor(Math.random() * 100);
|
||||
|
||||
let propostion = parseInt(prompt("Devinez le nombre caché entre 1 et 100 :"));
|
||||
|
||||
while (propostion != nombreCache) {
|
||||
|
||||
if (propostion < nombreCache) console.log("C'est plus grand !");
|
||||
else if (propostion > nombreCache) console.log("C'est plus petit !");
|
||||
|
||||
propostion = prompt("Réessayez :");
|
||||
}
|
||||
|
||||
if (propostion == nombreCache) console.log("Bravo ! Vous avez deviné le nombre caché !");
|
||||
45
algo_js/package-lock.json
generated
Normal file
45
algo_js/package-lock.json
generated
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "algo_js",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "algo_js",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"prompt-sync": "^4.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/ansi-regex": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz",
|
||||
"integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/prompt-sync": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/prompt-sync/-/prompt-sync-4.2.0.tgz",
|
||||
"integrity": "sha512-BuEzzc5zptP5LsgV5MZETjDaKSWfchl5U9Luiu8SKp7iZWD5tZalOxvNcZRwv+d2phNFr8xlbxmFNcRKfJOzJw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"strip-ansi": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/strip-ansi": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz",
|
||||
"integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ansi-regex": "^4.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
13
algo_js/package.json
Normal file
13
algo_js/package.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "algo_js",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "cafe.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"prompt-sync": "^4.2.0"
|
||||
}
|
||||
}
|
||||
22
algo_js/palindrome.js
Normal file
22
algo_js/palindrome.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const prompt = require('prompt-sync')();
|
||||
|
||||
// Palindromes
|
||||
|
||||
let word = prompt("Entrez une chaîne de caractères : ");
|
||||
|
||||
if (isPalindrome(word)) console.log(word + " est un palindrome.");
|
||||
else console.log(word + " n'est pas un palindrome.");
|
||||
|
||||
function isPalindrome(word) {
|
||||
|
||||
let left = 0;
|
||||
let right = word.length - 1;
|
||||
|
||||
for (let i = 1; i < word.length; i++) {
|
||||
//console.log("Left: " + word[left] + "(" + left + ")" + " Right: " + word[right] + "(" + right + ")");
|
||||
if (word[left] !== word[right]) return false;
|
||||
left++;
|
||||
right--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
10
algo_js/somme.js
Normal file
10
algo_js/somme.js
Normal file
@@ -0,0 +1,10 @@
|
||||
// Somme des n premiers entiers
|
||||
|
||||
let n = parseInt(prompt("Entrez un nombre entier positif : "));
|
||||
let somme = 0;
|
||||
|
||||
for (let i = 1; i <= n; i++) {
|
||||
somme += i;
|
||||
}
|
||||
|
||||
alert("La somme des " + n + " premiers entiers est : " + somme);
|
||||
28
algo_js/spirale.js
Normal file
28
algo_js/spirale.js
Normal 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;
|
||||
}
|
||||
28
algo_js/tableau_dichotomie.js
Normal file
28
algo_js/tableau_dichotomie.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const prompt = require('prompt-sync')();
|
||||
|
||||
// Recherche dichotomique
|
||||
|
||||
let table = [1,5,23,26,35,39,46,53,68,79,90];
|
||||
let nombre = parseInt(prompt("Entrez un nombre à rechercher: "));
|
||||
|
||||
let debut = 0;
|
||||
let fin = table.length - 1;
|
||||
45
|
||||
while (debut <= fin) {
|
||||
|
||||
if (!table.includes(nombre)) {
|
||||
console.log(nombre + " n'est pas dans le tableau !")
|
||||
break;
|
||||
}
|
||||
|
||||
let milieu = Math.floor((debut + fin) / 2);
|
||||
console.log("Recherche entre " + table[debut] + " et " + table[fin]);
|
||||
|
||||
if (table[milieu] === nombre) {
|
||||
console.log("Trouvé ! : " + nombre)
|
||||
break;
|
||||
|
||||
} else if (table[milieu] < nombre) debut = milieu + 1;
|
||||
|
||||
else fin = milieu - 1;
|
||||
}
|
||||
12
algo_js/tableau_min_max.js
Normal file
12
algo_js/tableau_min_max.js
Normal file
@@ -0,0 +1,12 @@
|
||||
// Min et max tableau
|
||||
|
||||
let min = table[0];
|
||||
let max = table[0];
|
||||
|
||||
for (let i = 0; i < table.length; i++) {
|
||||
if(table[i] < min) min = table[i];
|
||||
else if (table[i] > max) max = table[i];
|
||||
}
|
||||
|
||||
console.log("Min: " + min);
|
||||
console.log("Max: " + max);
|
||||
17
algo_js/tableau_tri.js
Normal file
17
algo_js/tableau_tri.js
Normal file
@@ -0,0 +1,17 @@
|
||||
// Tri tableau
|
||||
|
||||
let table = [17, 22, 43, 61, 45, 49, 8, 27, 62];
|
||||
|
||||
for (let i = 0; i < table.length; i++) {
|
||||
|
||||
for (let j = i+1; j < table.length; j++) {
|
||||
|
||||
if (table[i] > table[j]) {
|
||||
let temp = table[i];
|
||||
table[i] = table[j];
|
||||
table[j] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log(table)
|
||||
|
||||
Reference in New Issue
Block a user