first commit with existing project files
This commit is contained in:
33
algo
Normal file
33
algo
Normal file
@@ -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
|
||||
12
algo carré
Normal file
12
algo carré
Normal file
@@ -0,0 +1,12 @@
|
||||
a entier
|
||||
|
||||
debut
|
||||
|
||||
ecrire "Entrer un nombre: "
|
||||
lire a
|
||||
|
||||
a = a * a
|
||||
|
||||
afficher a
|
||||
|
||||
fin
|
||||
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)
|
||||
|
||||
43
exo algo
Normal file
43
exo algo
Normal file
@@ -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
|
||||
50
exo date valide.txt
Normal file
50
exo date valide.txt
Normal file
@@ -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
|
||||
90
exo pseudo code.txt
Normal file
90
exo pseudo code.txt
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user