From f758b29409ece56575ceb4c28d3e79324363a7dc Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 10 Oct 2022 17:12:50 +0200 Subject: [PATCH] =?UTF-8?q?Resoultion=20du=20probl=C3=A8me=20des=20boucles?= =?UTF-8?q?=20infinis=20+=20ajout=20des=20pages=20pour=20l'=C3=A9nigme=20c?= =?UTF-8?q?huckNorris=20+=20mise=20=C3=A0=20jour=20des=20pages=20pour=20l'?= =?UTF-8?q?=C3=A9nigme=20palindrome?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{chucknorris.py => chuckNorris.py} | 0 EnigmePython/codeCesarEncodage.py | 30 +++ brythonRunner/css/{palindrome.css => all.css} | 0 brythonRunner/javascript/chuckNorris.js | 192 ++++++++++++++++++ brythonRunner/javascript/palindrome.js | 43 ++-- brythonRunner/page/chuckNorris.html | 59 ++++++ brythonRunner/page/palindrome.html | 2 +- 7 files changed, 300 insertions(+), 26 deletions(-) rename EnigmePython/{chucknorris.py => chuckNorris.py} (100%) create mode 100644 EnigmePython/codeCesarEncodage.py rename brythonRunner/css/{palindrome.css => all.css} (100%) create mode 100644 brythonRunner/javascript/chuckNorris.js create mode 100644 brythonRunner/page/chuckNorris.html diff --git a/EnigmePython/chucknorris.py b/EnigmePython/chuckNorris.py similarity index 100% rename from EnigmePython/chucknorris.py rename to EnigmePython/chuckNorris.py diff --git a/EnigmePython/codeCesarEncodage.py b/EnigmePython/codeCesarEncodage.py new file mode 100644 index 00000000..34736439 --- /dev/null +++ b/EnigmePython/codeCesarEncodage.py @@ -0,0 +1,30 @@ +def Encrypt(text, key): + result = "" + for i in range(len(text)): + char = text[i] + if(char==" "): + result+=" " + elif (char.isupper()): + result += chr((ord(char) + key-65) % 26 + 65) + else: + result += chr((ord(char) + key - 97) % 26 + 97) + return result + + + +def Decrypt(text, key): + result = "" + for i in range(len(text)): + char = text[i] + if(char==" "): + result+=" " + elif (char.isupper()): + result += chr((ord(char) - key-65) % 26 + 65) + else: + result += chr((ord(char) - key - 97) % 26 + 97) + return result + + + +print(Encrypt("Hello world", 29)) +print(Decrypt("Khoor zruog", 29)) diff --git a/brythonRunner/css/palindrome.css b/brythonRunner/css/all.css similarity index 100% rename from brythonRunner/css/palindrome.css rename to brythonRunner/css/all.css diff --git a/brythonRunner/javascript/chuckNorris.js b/brythonRunner/javascript/chuckNorris.js new file mode 100644 index 00000000..d54036b2 --- /dev/null +++ b/brythonRunner/javascript/chuckNorris.js @@ -0,0 +1,192 @@ +function run() { + const terminal = document.getElementById("console"); + const runner = new BrythonRunner({ + stdout: { + write(content) { + terminal.innerHTML += content; + terminal.scrollTop = terminal.scrollHeight; + }, + flush() {} + }, + stderr: { + write(content) { + terminal.innerHTML += content; + terminal.scrollTop = terminal.scrollHeight; + }, + flush() {} + }, + stdin: { + async readline() { + terminal.innerHTML += "\n"; + terminal.scrollTop = terminal.scrollHeight; + var userInput = prompt(); + return userInput; + }, + flush() {} + } + }); + var code = editor.getValue(); + runner.runCode(code); + setTimeout(() => { + runner.stopRunning(); + }, 10*1000); +} + +function run_init() { + if (document.getElementById("console") != '') { + document.getElementById("console").innerHTML = ''; + } + run(); +} + +var editor = ace.edit("editor"); +editor.setTheme("ace/theme/vibrant_ink"); +editor.getSession().setMode("ace/mode/python"); +editor.setFontSize("16px"); +editor.container.style.height = "250px" +editor.setOptions({ + enableLiveAutocompletion: true, + copyWithEmptySelection: true, + showGutter: true, + useWrapMode: true, // wrap text to view + indentedSoftWrap: false, +}); + +//Function that execute given code and return the result in a given element by id + +function exec(code, id) { + const terminal = document.getElementById("console"); + const runner = new BrythonRunner({ + stdout: { + write(content) { + if (id == "code"){ + retourCode = content; + } + if (id == "solution"){ + retourSolution = content; + } + }, + flush() {} + }, + stderr: { + write(content) { + if (id == "solution"){ + retourSolution = "ERROR"; + } + terminal.innerHTML += content; + terminal.scrollTop = terminal.scrollHeight; + }, + flush() {} + }, + stdin: { + async readline() { + terminal.innerHTML += "\n"; + terminal.scrollTop = terminal.scrollHeight; + var userInput = prompt(); + return userInput; + }, + flush() {} + } + }); + runner.runCode(code) + setTimeout(() => { + runner.stopRunning(); + }, 10*1000); +} + +//~ Function that check if the code in the editor as the same result as the solution. + +function check(){ + if (retourSolution == "ERROR") { + result.innerHTML = "Il semblerait qu'il y a une erreur dans ton code :/"; + result.classList.remove('hidden'); + } + + else if (retourSolution == retourCode) { + result.innerHTML = "Bien joué"; + result.classList.remove('hidden'); + } + else { + result.innerHTML = "Mauvaise réponse"; + result.classList.remove('hidden'); + } +} + +//~ Function that test the user code + +async function submit(){ + var test = editor.getValue()+`\n +import random as r +def binaire2unitaireVerif(x): + rep=0 + pre=x[0] + unitaire="" + for i in x: + if(pre==i): + rep+=1 + else: + if(pre=="1"): + unitaire=unitaire+"0 " + else: + unitaire=unitaire+"00 " + for j in range(rep): + unitaire=unitaire+"0" + unitaire=unitaire+" " + rep=1 + pre=i + if(pre=="1"): + unitaire=unitaire+"0 " + else: + unitaire=unitaire+"00 " + for i in range(rep): + unitaire=unitaire+"0" + return unitaire + +def testChuckNorris(x): + l="0000000" + if(binaire2unitaire(l)!="00 0000000"): + return False + l="1111111" + if(binaire2unitaire(l)!="0 0000000"): + return False + l="1101001" + if(binaire2unitaire(l)!="0 00 00 0 0 0 00 00 0 0"): + return False + l="" + for i in range(x): + for j in range(r.randint(1,10)): + l=l+str(r.randint(0,1)) + if(binaire2unitaire(l)!=binaire2unitaireVerif(l)): + return False + l="" + return True + +print(testChuckNorris(5)) + `; + exec("print ('True')", "code"); + exec(test, "solution"); + await new Promise(r => setTimeout(r, 1500)); + check(); +} + +function aide(){ + if(document.getElementById("textAide").textContent == ""){ + document.getElementById("textAide").textContent = "Bonne chance :)"; + } + else{ + document.getElementById("textAide").textContent = ""; + } +} + +function rappel(){ + if(document.getElementById("textRappel").textContent == ""){ + document.getElementById("textRappel").textContent = ` + Dans le codage Chuck Norris, le '0' est codé '00' et le '1' est codé '0'. Puis un espace, puis ensuite autant de '0' que le message contient de '0' ou '1' successifs. + Par exemple, la suite "10000111" sera traduite de la façon suivante : "0 0 00 0000 0 000 + ` +} + else{ + document.getElementById("textRappel").textContent = ""; + } +} + diff --git a/brythonRunner/javascript/palindrome.js b/brythonRunner/javascript/palindrome.js index ba76c856..ed728bab 100644 --- a/brythonRunner/javascript/palindrome.js +++ b/brythonRunner/javascript/palindrome.js @@ -1,29 +1,24 @@ -function Abort() -{ - throw new Error('This is not an error. This is just to abort javascript'); -} - function run() { - const console = document.getElementById("console"); + const terminal = document.getElementById("console"); const runner = new BrythonRunner({ stdout: { write(content) { - console.innerHTML += content; - console.scrollTop = console.scrollHeight; + terminal.innerHTML += content; + terminal.scrollTop = terminal.scrollHeight; }, flush() {} }, stderr: { write(content) { - console.innerHTML += content; - console.scrollTop = console.scrollHeight; + terminal.innerHTML += content; + terminal.scrollTop = terminal.scrollHeight; }, flush() {} }, stdin: { async readline() { - console.innerHTML += "\n"; - console.scrollTop = console.scrollHeight; + terminal.innerHTML += "\n"; + terminal.scrollTop = terminal.scrollHeight; var userInput = prompt(); return userInput; }, @@ -31,21 +26,17 @@ function run() { } }); var code = editor.getValue(); - runner.runCode(code) - } - -function run_init() { + runner.runCode(code); + setTimeout(() => { + runner.stopRunning(); + }, 10*1000); +} + +function run_init() { if (document.getElementById("console") != '') { document.getElementById("console").innerHTML = ''; - run(); - //setTimeout(() => {console.log("Resolve while pb")}, 1000); - //setTimeout(() => {Abort()}, 5000); - } - else { - run(); - //setTimeout(() => {console.log("Resolve while pb")}, 1000); - //setTimeout(() => {Abort()}, 5000); } + run(); } var editor = ace.edit("editor"); @@ -65,7 +56,6 @@ editor.setOptions({ function exec(code, id) { const terminal = document.getElementById("console"); - const retour = document.getElementById(id); const runner = new BrythonRunner({ stdout: { write(content) { @@ -99,6 +89,9 @@ function exec(code, id) { } }); runner.runCode(code) + setTimeout(() => { + runner.stopRunning(); + }, 10*1000); } //~ Function that check if the code in the editor as the same result as the solution. diff --git a/brythonRunner/page/chuckNorris.html b/brythonRunner/page/chuckNorris.html new file mode 100644 index 00000000..3cb540b8 --- /dev/null +++ b/brythonRunner/page/chuckNorris.html @@ -0,0 +1,59 @@ + + + + + + + Brython + + + +
+

+ Coder un fonction binaire2unaire qui prend en argument un nombre binaire et le code via le codage Chucknorris. +

+
+ +

+ + + + + +

+

+
def binaire2unitaire(x): + rep=0 + pre=x[0] + unitaire="" + for i in x: + if(pre==i): + rep+=1 + else: + if(pre=="1"): + unitaire=unitaire+"0 " + else: + unitaire=unitaire+"00 " + for j in range(rep): + unitaire=unitaire+"0" + unitaire=unitaire+" " + rep=1 + pre=i + if(pre=="1"): + unitaire=unitaire+"0 " + else: + unitaire=unitaire+"00 " + for i in range(rep): + unitaire=unitaire+"0" + return unitaire +
+
+ +
+ + + + + + + diff --git a/brythonRunner/page/palindrome.html b/brythonRunner/page/palindrome.html index 176bdf47..d70134a5 100644 --- a/brythonRunner/page/palindrome.html +++ b/brythonRunner/page/palindrome.html @@ -5,7 +5,7 @@ Brython - +