Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*zad1*)
- let filtering list_lists value =
- match list_lists with
- |[]->[]
- |_ -> List.filter(fun x-> List.filter(fun y -> y=value)x <> []) list_lists;;
- filtering [[1;2;3];[3;4];[5;6]] 3;;
- filtering [[1;2;4;5;6;7];[1;1;1;1;4];[5;6];[5;6;7;5;76;7;54];[5;6;5;4;3];[5;6]] 3;;
- filtering [[1;2;4;5;6;7];[1;1;1;1;4];[5;6];[5;6;7;5;76;7;54];[5;6;5;4];[5;6]] 3;;
- filtering [] 5;;
- (*zad2*)
- let binary list =
- List.fold_left (fun acc x -> acc*2 + x) 0 list;;
- binary [1;1;1;0];;
- binary [1;1;1;0;1];;
- binary [];;
- binary [0;0;0;0;0;0;1];;
- (*inaczej*)
- let bin2dec lb =
- List.fold_left (fun acc b -> acc*2 + b) 0 lb;;
- bin2dec [1;1;1;0;1];;
- let binarny list=
- let rec binarny1(lista, wynik, index) =
- match lista with
- | [] -> wynik
- | h::t ->
- if h = 0 then binarny1(t, wynik, index+.1.)
- else let p = 2.**index in binarny1(t, wynik+.p, index+.1.)
- in binarny1(List.rev list,0.,0.);;
- binarny [1;1;1;0;1];;
- (*zad3*)
- (*not tail-recursive*)
- let modulus tuple=
- List.map (fun (x,y,z)-> (abs(x),abs(y),abs(z))) tuple;;
- (*tail-recursive*)
- let modulus tuple=
- let rec modulus_2 (tuple2, list) =
- match tuple2 with
- | [] -> List.rev list
- | (a,b,c)::t -> modulus_2(t,(abs(a),abs(b),abs(c))::list)
- in modulus_2 (tuple, []);;
- modulus [(-1,-2,-3);(-1,2,4)];;
- modulus [(-1,-2,-3);(-1,2,4);(0,0,-10)];;
- modulus [];;
- let binary list =
- List.fold_left (fun acc x -> acc*2 + x) 0 list;;
- let rec jakasFunkcja2 x y = List.rev(List.fold_left (fun acc h1 -> h1::a) [] y x);;
- let rec jakasFunkcja2 x y = List.rev(List.fold_left (fun a (x as h1::t1 -> (h2,h1)::a) [] y x);;
- jakasFunkcja2 [1;2;3] [4;5;6];;
Advertisement
Add Comment
Please, Sign In to add comment