You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1021 B
38 lines
1021 B
//~ Function that test the user code
|
|
|
|
async function submit(){
|
|
var test = editor.getValue()+`\n
|
|
import random as r
|
|
def hanoi_rec(l,nb_disks, start, middle, end):
|
|
if(nb_disks == 1):
|
|
return l.append([start,end])
|
|
else:
|
|
hanoi_rec(l,nb_disks - 1, start, end, middle)
|
|
l.append([start,end])
|
|
hanoi_rec(l,nb_disks - 1, middle, start, end)
|
|
|
|
def hanoiVerif(nb_disks,start, middle, end):
|
|
l=[]
|
|
hanoi_rec(l,nb_disks,start, middle, end)
|
|
return l
|
|
|
|
def testhanoi(x):
|
|
hanoi(1,"A","B","C")
|
|
if(hanoi(3,"A","B","C")!=[['A','C'],['A','B'],['C','B'],['A','C'],['B','A'],['B','C'],['A','C']]):
|
|
return False
|
|
for i in range(x):
|
|
j=r.randint(1,4)
|
|
if(hanoi(j,"Z","E","R")!=hanoiVerif(j,"Z","E","R")):
|
|
return False
|
|
return True
|
|
|
|
print(testhanoi(5))
|
|
`;
|
|
exec("print ('True')", "code");
|
|
exec(test, "solution");
|
|
result.innerHTML = "Test en cours...";
|
|
await new Promise(r => setTimeout(r, 1500));
|
|
check();
|
|
}
|
|
|
|
|