Skip to content

Instantly share code, notes, and snippets.

@blackh
Created February 6, 2012 22:07
Show Gist options
  • Save blackh/1755272 to your computer and use it in GitHub Desktop.
Save blackh/1755272 to your computer and use it in GitHub Desktop.
TD 2 PUBLIC
let rec dicho v l = match (vect_length v) with
|1 -> (v.(0) = l)
|n -> if ((n mod 2) = 0) then (
if (v.(n/2) <= l) then (dicho (sub_vect v (n/2) (n/2)) l)
else (dicho (sub_vect v 0 (n/2)) l);)
else (if(v.(n-1) = l) then true else (dicho (sub_vect v 0 (n-1)) l));;
dicho [|2;3;4;5|] 5;;
(* (* (* (* (* *) *) *) *) *)
let rec mlaux l1 l2 = match l1 with
| [] -> l2
| _ -> (mlaux (tl l1) ((hd l1)::l2));;
let mir_list l = mlaux l [];;
mir_list [2;3;4;5;6];;
(* (* *) *)
let repete l = let m = (mlaux l []) in (mlaux m l);;
repete [2;3;4;5;6];;
(* (* *) *)
let rec baux l1 l2 = match l1 with
| [] -> l2
| _ -> (baux (tl l1) ((hd l1)::(hd l1)::l2));;
let begaye l = mir_list(baux l []);;
let rec begaye l = match l with
| [] -> []
| h::q -> h::h::(begaye (tl l));;
begaye [2;3;4;5;6];;
(* SUPPRIME LES N PREMIERS ELEMENTS *)
let rec sub_list l n = match (list_length l) with
| m when m=n -> l
| _ -> sub_list (tl l) n;;
let rec list_egal l s = match (list_length s) with
|0 -> true
|n -> if((hd l)=(hd s)) then list_egal (tl l) (tl s) else false;;
let eteper l =
let n = list_length l in
if((n mod 2)=1) then (failwith "RATE");
let s = sub_list l (n/2) in
if (list_egal l s) then s else (failwith "RATE");;
eteper [2;2;4;2;2;4];;
eteper [2;1;4;2;2;4];;
eteper [2;2;4;2;1;4];;
(* (* (* (* *) *) *) *)
let rec testb l = match (list_length l) with
|2 -> (hd l = (hd (tl l)))
|n -> if(hd l = (hd (tl l))) then testb (tl (tl l)) else false;;
testb [2;2;4;2;4;4];;
testb [2;2;4;4;4;4];;
let rec eyageb_aux l1 l2 = match (list_length l1) with
|0 -> l2
|n -> eyageb_aux (tl (tl l1)) ((hd (tl l1))::l2);;
let eyageb l =
let n = list_length l in
if((n mod 2)=1 or not(testb l)) then (failwith "RATE");
mir_list (eyageb_aux l []);;
eyageb [2;2;4;4;4;4];;
eyageb [2;1;4;2;4;4];;
(* (* (* (* (* (* (* *) *) *) *) *) *) *)
let rec gint n = match n with
| n when (n < 0) -> (n-1)
| _ -> gint (2*n);;
(* (* (* (* (* (* (* *) *) *) *) *) *) *)
let rec iter f n x = match n with
| 1 -> f 1 x
| n -> f n (iter f (n-1) x);;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment