From c8e200b42f8d1f747d26e0926b7fbcee59e0dfea Mon Sep 17 00:00:00 2001 From: Vincent Guillet Date: Wed, 2 Apr 2025 11:33:15 +0200 Subject: [PATCH] first commit with existing project files --- algo | 33 +++++++++++++ algo carré | 12 +++++ algo_js/cafe.js | 12 +++++ algo_js/chiffre_cesar.js | 52 ++++++++++++++++++++ algo_js/escaliers.js | 19 ++++++++ algo_js/multiplication.js | 12 +++++ algo_js/nombre_cache.js | 17 +++++++ algo_js/package-lock.json | 45 ++++++++++++++++++ algo_js/package.json | 13 +++++ algo_js/palindrome.js | 22 +++++++++ algo_js/somme.js | 10 ++++ algo_js/spirale.js | 28 +++++++++++ algo_js/tableau_dichotomie.js | 28 +++++++++++ algo_js/tableau_min_max.js | 12 +++++ algo_js/tableau_tri.js | 17 +++++++ exo algo | 43 +++++++++++++++++ exo date valide.txt | 50 +++++++++++++++++++ exo pseudo code.txt | 90 +++++++++++++++++++++++++++++++++++ 18 files changed, 515 insertions(+) create mode 100644 algo create mode 100644 algo carré create mode 100755 algo_js/cafe.js create mode 100644 algo_js/chiffre_cesar.js create mode 100644 algo_js/escaliers.js create mode 100644 algo_js/multiplication.js create mode 100644 algo_js/nombre_cache.js create mode 100644 algo_js/package-lock.json create mode 100644 algo_js/package.json create mode 100644 algo_js/palindrome.js create mode 100644 algo_js/somme.js create mode 100644 algo_js/spirale.js create mode 100644 algo_js/tableau_dichotomie.js create mode 100644 algo_js/tableau_min_max.js create mode 100644 algo_js/tableau_tri.js create mode 100644 exo algo create mode 100644 exo date valide.txt create mode 100644 exo pseudo code.txt diff --git a/algo b/algo new file mode 100644 index 0000000..4363390 --- /dev/null +++ b/algo @@ -0,0 +1,33 @@ +a entier +b entier + +c entier + +debut + +a = 5 +b = 7 + +c = a //c = 5 +a = b //a = 7 +b = c //b = 5 + + +fin + +----------------------------- + +a entier +b entier + +debut + +a = 5 +b = 7 + +b = b - a //b = 2 +a = a + b //a = 7 +b = a - b //b = 5 + + +fin diff --git a/algo carré b/algo carré new file mode 100644 index 0000000..588aad8 --- /dev/null +++ b/algo carré @@ -0,0 +1,12 @@ +a entier + +debut + +ecrire "Entrer un nombre: " +lire a + +a = a * a + +afficher a + +fin \ No newline at end of file diff --git a/algo_js/cafe.js b/algo_js/cafe.js new file mode 100755 index 0000000..51645d5 --- /dev/null +++ b/algo_js/cafe.js @@ -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"); \ No newline at end of file diff --git a/algo_js/chiffre_cesar.js b/algo_js/chiffre_cesar.js new file mode 100644 index 0000000..6959775 --- /dev/null +++ b/algo_js/chiffre_cesar.js @@ -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]); + } +} \ No newline at end of file diff --git a/algo_js/escaliers.js b/algo_js/escaliers.js new file mode 100644 index 0000000..e9d3791 --- /dev/null +++ b/algo_js/escaliers.js @@ -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) +} \ No newline at end of file diff --git a/algo_js/multiplication.js b/algo_js/multiplication.js new file mode 100644 index 0000000..41839f9 --- /dev/null +++ b/algo_js/multiplication.js @@ -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); \ No newline at end of file diff --git a/algo_js/nombre_cache.js b/algo_js/nombre_cache.js new file mode 100644 index 0000000..a4dd859 --- /dev/null +++ b/algo_js/nombre_cache.js @@ -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é !"); \ No newline at end of file diff --git a/algo_js/package-lock.json b/algo_js/package-lock.json new file mode 100644 index 0000000..8c75919 --- /dev/null +++ b/algo_js/package-lock.json @@ -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" + } + } + } +} diff --git a/algo_js/package.json b/algo_js/package.json new file mode 100644 index 0000000..88110f3 --- /dev/null +++ b/algo_js/package.json @@ -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" + } +} diff --git a/algo_js/palindrome.js b/algo_js/palindrome.js new file mode 100644 index 0000000..d3c8c4c --- /dev/null +++ b/algo_js/palindrome.js @@ -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; +} \ No newline at end of file diff --git a/algo_js/somme.js b/algo_js/somme.js new file mode 100644 index 0000000..d9aa4fe --- /dev/null +++ b/algo_js/somme.js @@ -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); \ No newline at end of file diff --git a/algo_js/spirale.js b/algo_js/spirale.js new file mode 100644 index 0000000..8de5957 --- /dev/null +++ b/algo_js/spirale.js @@ -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; +} diff --git a/algo_js/tableau_dichotomie.js b/algo_js/tableau_dichotomie.js new file mode 100644 index 0000000..dbaf698 --- /dev/null +++ b/algo_js/tableau_dichotomie.js @@ -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; +} \ No newline at end of file diff --git a/algo_js/tableau_min_max.js b/algo_js/tableau_min_max.js new file mode 100644 index 0000000..fbf4038 --- /dev/null +++ b/algo_js/tableau_min_max.js @@ -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); \ No newline at end of file diff --git a/algo_js/tableau_tri.js b/algo_js/tableau_tri.js new file mode 100644 index 0000000..64449c4 --- /dev/null +++ b/algo_js/tableau_tri.js @@ -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) + diff --git a/exo algo b/exo algo new file mode 100644 index 0000000..7835035 --- /dev/null +++ b/exo algo @@ -0,0 +1,43 @@ +j entier +m entier +a entier +b booléen + +DEBUT + +ECRIRE "Entrez un jour" +LIRE j +ECRIRE "Entrez un mois" +LIRE m +ECRIRE "Entrez une année" +LIRE a + +SI (j <= 0 OU j > 31) OU (m <= 0 OU m > 12) OU (a <= 0) ALORS + ECRIRE "Erreur dans la date" +SINON + SI ((a%4 == 0 ET a%100 != 0) OU (a%400 == 0)) ALORS + b = VRAI // Année bissextile + SINON + b = FAUX // Année non bissextile + FINSI + + SI (m == 2) ALORS + SI (b == VRAI ET j <= 29) OU (b == FAUX ET j <= 28) ALORS + ECRIRE "Date valide" + SINON + ECRIRE "Erreur dans la date" + FINSI + SINON SI (m == 4 OU m == 6 OU m == 9 OU m == 11) ALORS + SI (j <= 30) ALORS + ECRIRE "Date valide" + SINON + ECRIRE "Erreur dans la date" + FINSI + SINON + SI (j <= 31) ALORS + ECRIRE "Date valide" + SINON + ECRIRE "Erreur dans la date" + FINSI + FINSI +FINSI \ No newline at end of file diff --git a/exo date valide.txt b/exo date valide.txt new file mode 100644 index 0000000..cb4d6e8 --- /dev/null +++ b/exo date valide.txt @@ -0,0 +1,50 @@ +j entier +m entier +a entier +b booléen + +DEBUT + +ECRIRE "Entrez un jour" +LIRE j + +ECRIRE "Entrez un mois" +LIRE m + +ECRIRE "Entrez une année" +LIRE a + +SI (j <= 0 OU j > 31) OU (m <= 0 OU m > 12) OU (a <= 0) ALORS + ECRIRE "Erreur dans la date" + +SINON + SI ((a%4 == 0 ET a%100 != 0) OU (a%400 == 0)) ALORS + b = VRAI // Année bissextile + SINON + b = FAUX // Année non bissextile + FINSI + + SI (m == 2) ALORS + SI (b == VRAI ET j <= 29) OU (b == FAUX ET j <= 28) ALORS + ECRIRE "Date valide" + SINON + ECRIRE "Erreur dans la date" + FINSI + + SINON SI (m == 4 OU m == 6 OU m == 9 OU m == 11) ALORS + SI (j <= 30) ALORS + ECRIRE "Date valide" + SINON + ECRIRE "Erreur dans la date" + FINSI + + SINON + SI (j <= 31) ALORS + ECRIRE "Date valide" + SINON + ECRIRE "Erreur dans la date" + FINSI + + FINSI + +FINSI \ No newline at end of file diff --git a/exo pseudo code.txt b/exo pseudo code.txt new file mode 100644 index 0000000..8b6f19e --- /dev/null +++ b/exo pseudo code.txt @@ -0,0 +1,90 @@ +a entier + +DEBUT + +ECRIRE "Entrez un nombre" + +LIRE a + +SI a < 0 ALORS + ECRIRE a . " est négatif" +SINON SI a > 0 ALORS + ECRIRE a . " est positif" +SINON + ECRIRE a . " est égal à 0" +FINSI + +FIN + + +---------------------------------- + +a entier +b entier + +DEBUT + +ECRIRE "Entrez deux nombres" + +LIRE a +LIRE b + +SI ((a < 0) OU (b < 0)) OU !((a < 0) ET (b < 0)) +ALORS ECRIRE "Le produit de " a . " par " . b " est négatif" +SINON ECRIRE "Le produit de " a . " par " . b " est positif" +FINSI + +FIN + +---------------------------------- + +v entier +route chaine de caractères + +DEBUT + +ECRIRE "Entrez la valeur de la vitesse" +LIRE v + +ECRIRE "Entrez le type de route" +LIRE route + +SI (v > 130) OU + (route = "Départementale" ET v > 90 ) OU + ("Ville" ET v > 50) +ALORS + ECRIRE "Excès de vitesse !" + +SINON +ALORS + ECRIRE "Pas d'excès de vitesse." + +FINSI + +FIN + + +---------------------------------- + + +t entier +s entier +m entier +h entier + +DEBUT + +ECRIRE "Entrer le temps en millisecondes" +LIRE t + +ms = t%1000 //50 +t = (t - ms) / 1000 +s = t%60 //6 +t = (t - s) +m = t%60 //1 +t = (t - m) / 60 +h = t%60 //1 + +ECRIRE "Temps : h . "h " . m . "m " . s . "s " . ms . "ms" + +FIN \ No newline at end of file