Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let combine1 l =
- let rec aux acc lst = match lst with
- | [] -> acc
- | h::t -> aux (h@acc) t
- in aux [] (List.rev l)
- let combine2 l = List.fold_right (fun el acc -> el@acc) l []
- let combine3 l = List.fold_left (fun acc el -> el@acc) [] l
- let mylst = [[1;2]; [3;4;5]; []; [6]]
- let sumPair1 l =
- let rec aux acc1 acc2 lst = match lst with
- | [] -> (acc1, acc2)
- | h::t -> match h with
- | (a, b) -> aux (acc1+a) (acc2+b) t
- in aux 0 0 l
- let mylst2 = [(1, 2); (4, 5); (5, 7); (9, 11)]
- let sumPair2 l = List.fold_right (fun (a, b) (x, y) -> (x+a, y+b)) l (0, 0)
- let nrEl l = List.fold_right (fun el acc -> acc+1) l 0
- let maxLst l = List.fold_right (fun el acc -> if el > acc then el else acc) l 0
- let lstComp l1 l2 =
- let rec aux lst1 lst2 = match lst1, lst2 with
- | [], [] -> 0
- | [], a -> -1
- | a, [] -> 1
- | h1::t1, h2::t2 -> if h1 = h2 then aux t1 t2 else
- if h1 > h2 then 1 else -1
- in aux l1 l2
- let lsta = [1; 2; 3; 4]
- let fromTo a b =
- let rec aux acc n =
- if n = a then n::acc
- else aux (n::acc) (n-1)
- in aux [] b
- let xlst = fromTo 1 100
- let prod = List.fold_right
- (fun el acc -> if (el mod 2) != 0 then el * acc else acc) xlst 1
- let cuburi = List.fold_right
- (fun el acc -> if (el mod 5) = 0 then (el*el*el)+acc else acc) xlst 0
- module Int = struct
- type t = int
- let compare = compare
- end
- module IS = Set.Make(Int)
- let seta = IS.add 3 (IS.add 7 (IS.add 5 (IS.singleton(1))))
- let setb = IS.add 2 (IS.add 1 (IS.add 6 (IS.add 4 (IS.singleton(3)))))
- let myinter set1 set2 = IS.fold (fun el acc -> if IS.mem el set2 then IS.add el acc else acc) set1 IS.empty
- let myreun set1 set2 = IS.fold (fun el acc -> IS.add el acc) set1 set2
- let mydiff set1 set2 = IS.fold (fun el acc -> if not (IS.mem el set2) then IS.add el acc else acc) set1 IS.empty
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement