mirror of
https://github.com/Aviortheking/MasterMind.git
synced 2025-04-22 10:52:10 +00:00
Solution temporaire Nicolas non optimisé
This commit is contained in:
parent
578ba10425
commit
0a949e8180
15
.vscode/launch.json
vendored
Normal file
15
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "chrome",
|
||||
"request": "launch",
|
||||
"name": "Launch Chrome against localhost",
|
||||
"url": "http://localhost:8080",
|
||||
"webRoot": "${workspaceFolder}"
|
||||
}
|
||||
]
|
||||
}
|
31
temporarySolutionNicolas.js
Normal file
31
temporarySolutionNicolas.js
Normal file
@ -0,0 +1,31 @@
|
||||
let temporarySolution = [0,0,0,0]
|
||||
let round = 0;
|
||||
|
||||
function resolveMasterMind(solution){
|
||||
let random = 1;
|
||||
console.log('Solution à trouver = ', solution);
|
||||
while (!(JSON.stringify(solution)==JSON.stringify(temporarySolution))) {
|
||||
if (solution.includes(random)) {
|
||||
getPosition(random, solution)
|
||||
}
|
||||
round ++;
|
||||
random ++;
|
||||
}
|
||||
console.log('Solution trouvé par l\'algorithme = ', temporarySolution);
|
||||
console.log(`Solution trouvé au bout de ${round} rounds`);
|
||||
}
|
||||
|
||||
function getPosition(inputNumber, response){
|
||||
|
||||
for (let index = 0; index < response.length; index++) {
|
||||
round ++;
|
||||
if(inputNumber === response[index]){
|
||||
temporarySolution[index] = response[index];
|
||||
}
|
||||
}
|
||||
console.log('Solution temporaire', temporarySolution);
|
||||
|
||||
}
|
||||
|
||||
resolveMasterMind([2,4,5,1])
|
||||
|
Loading…
x
Reference in New Issue
Block a user