From 0a949e8180508439ad1001c7422007da2bc6a044 Mon Sep 17 00:00:00 2001 From: Neeko Date: Wed, 25 Nov 2020 18:55:00 +0100 Subject: [PATCH] =?UTF-8?q?Solution=20temporaire=20Nicolas=20non=20optimis?= =?UTF-8?q?=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 15 +++++++++++++++ temporarySolutionNicolas.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 temporarySolutionNicolas.js diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..6f3c990 --- /dev/null +++ b/.vscode/launch.json @@ -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}" + } + ] +} \ No newline at end of file diff --git a/temporarySolutionNicolas.js b/temporarySolutionNicolas.js new file mode 100644 index 0000000..305141a --- /dev/null +++ b/temporarySolutionNicolas.js @@ -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]) +