Hello ,
j'ai un piti probleme pour l'exercice 4 du qcm 2007:
Mon code marche pour les 8 premiers test, mais pour le 9 eme , un message d'erreur apparait: Fatal error: exception
Invalid_argument("Array.make")
Voici mon code
1 2 3 4 5 6 7 8 9 | let heritiere enfants k = let rec prochain=function(tab,n,k,l,total)->if k=total then n else if n+1=l then (if tab.(0)=1 then prochain(tab,0,k,l,total+1) else prochain(tab,0,k,l,total)) else if tab.(n+1)=1 then prochain(tab,n+1,k,l,total+1) else prochain(tab,n+1,k,l,total) in let rec position=function(tab,1)->0 |(tab,enfants)->if tab.(enfants-1)=1 then enfants-1 else position(tab,enfants-1)in |
let tab=Array.make enfants 1 in
1 2 3 4 5 6 7 8 9 | let rec tour=function(tab,1,a,j)->tab.(0)|(tab,n,a,j)->if tab.(a)=1 then (tab.(a) tour(tab,enfants,(k mod enfants)-1,k); position(tab,enfants) in let in_int () = Scanf.scanf " %d" (fun x->x) in let n = in_int() in let k = in_int() in Printf.printf "%d\n" (heritiere n k);; |
Merci d'avance
Ps: Sinon ,hs , mais les balises de code sont bizarre: à chaque saut de ligne on est obligé d'en remettre meme si la balise de fin de code n'a pas été mise