yu-gi > Quoi de neuf ?
euh…
let rec imprimer = fun [] -> ( );
| ( t::q)-> imprimer q; print_string t; print_newline();;
let soi = string_of_int;;
( * Fonction couples qui à une liste l associe la liste des couples ( [x;y],q)
où l= réunion de [x;y] et q *)
( * exo : determiner exactement ce que font ces fonctions *)
let rec recoller x liste = match liste with
[] -> [] | ( (a,w)::q) -> ( a,x::w)::(recoller x q);;
let rec accoupler x liste = match liste with
[] -> [] | ( t::q) -> ( [x;t],q)::(recoller t ( accoupler x q));;
let rec couples = fun
[] -> []
| [a] -> []
| ( t::q) -> ( accoupler t q)@(recoller t ( couples q));;
let rec compte_est_bon a cible h =
if mem cible a then begin imprimer h; failwith " c´est fini ! "; end
else match a with
[] -> failwith " erreur qui ne devrait pas se produire"
| [x] -> ( )
| a -> compte_aux ( couples a) cible h
and compte_aux liste cible h = match liste with
[] -> ( )
| ( ( [x;y],b)::q ) ->
let c=x+y in compte_est_bon ( c::b) cible ( ((soi x)^"+"^(soi y)^"="^(soi c))::h);
let c=x*y in compte_est_bon ( c::b) cible ( ((soi x)^"*"^(soi y)^"="^(soi c))::h);
let u=min x y and v = max x y in
begin
if u<>v then
let c=v-u in compte_est_bon ( c::b) cible ( ((soi v)^"-"^(soi u)^"="^(soi c))::h);
if u<>0 & v mod u =0 then
let c=v/u in compte_est_bon ( c::b) cible ( ((soi v)^"/"^(soi u)^"="^(soi c))::h);
end;
compte_aux q cible h;
| _ -> failwith " pas d´autre cas possible en principe ! " ; ;
let c_e_b a cible = compte_est_bon a cible [];
failwith " aucune solution à l´horizon " ;;
( * tests *)
let f = fun 11 -> 25 |12 -> 50 |13 -> 75 |14 -> 100|n -> n;;
let rec tirage = fun
0 -> []
| n -> ( f ( (random__int 14) +1) ) :: ( tirage ( n-1) ) ;;
( * tirages parmi 1,2,3,4,5,6,7,8,9,10,25,50,75,100 *)
let a = tirage 6;;
let cible=random__int 1000;;
c_e_b a cible ; ;
est-elle une réponse convenable ?
coucou ganda
ca va ?