Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1
- //a
- let tris_same_shoulders (a:float) (h:float) =
- let area = (a*h)/2.0
- let circuit_xd =
- let diag = sqrt ( (h*h) + (a/2.0)*(a/2.0))
- 2.0*diag + a
- (area, circuit_xd)
- //b
- let six_corner (a:float) = (3.0* a*a *sqrt(a) )/2.0
- printf "exc.1-a %A" (tris_same_shoulders 4.0 2.0)
- printf "exc.1-b %A" (six_corner 2.0)
- //2--
- let rec x_n x n buff=
- if n>0 then x_n x (n-1) (buff+x) else buff
- printf "exc.2 %A" (x_n 2 4 0)
- //3-
- let rec x_M_n x n buff=
- if n>0 then x_M_n x (n-1) buff*x else buff
- printf "exc.3 %A" (x_M_n 2 4 1)
- //4-
- let rec e_s_l list bb =
- match list with
- | x::r -> (e_s_l r (x::rest) )
- | [] -> rest
- printf "exc.4 %A" (e_s_l [1;2;3;4;5;6;7;8;9] [])
- let rec e_s_l list buff bb =
- match list with
- | x::r -> if bb=true then (e_s_l r (x::buff) false) else (e_s_l r buff true)
- | [] -> List.rev buff
- printf "exc.4 %A" (e_s_l [1;2;3;4;5;6;7;8;9] [] true)
- //5-
- let rec_hr list =
- let bb = true
- list |> List.indexed|> List.filter(fun (i, x) -> i%2=0 ) |> List.map (fun (i, x) -> (x))
- printf "exc.5 %A" (rec_hr [1;2;3;4;5;6;7;8;9] )
- //6-
- let rec filter_by_n list buff n =
- match list with
- | x::r -> if x%n=0 then (filter_by_n r (x::buff) n) else (filter_by_n r buff n)
- | [] -> List.rev buff
- printf "exc.6 %A" (filter_by_n [1;2;3;4;5;6;7;8;9] [] 3)
- //7-
- let rec_hr list n = List.filter(fun x -> x%n=0 ) list
- printf "exc.7 %A" (rec_hr [1;2;3;4;5;6;7;8;9] 3)
- //8-
- type ksiazka = {
- tytul : string;
- autor : string;
- data_wydania : string;
- wydawnictwo : string;
- lista_stron : int;
- oprawka_twarda : bool;
- }
- //9-
- let min_max_rec list =
- let rec min list got =
- match list with
- | x::rest -> if x<got then min rest x else min rest got
- | [] -> got
- let rec max list got =
- match list with
- | x::rest -> if x>got then max rest x else max rest got
- | [] -> got
- (min list list.[0], max list list.[0])
- printfn "ex.9 %A" (min_max_rec [3;2;1;5;8;2])
- //10-
- let min_max list = (List.min list, List.max list)
- printfn "ex.10 %A" (min_max [3;2;1;5;8;2])
- //11-
- let average_rec list =
- let rec sum list got=
- match list with
- |x::rest -> sum rest (x + got)
- |[] -> got
- (sum list 0) / (List.length list)
- //printfn "ex 11 %A" (average_rec [1;2;3;4])
- //12-
- let average_high list =
- let sum list = List.fold (+) 0 list
- (float (sum list))/(float (List.length list))
- printfn "ex 12 %A" (average_high [1;2;3;4])
- //13-
- let rec count_less list n count =
- match list with
- | x::rest ->if x<n then count_less rest n (count+1) else count_less rest n count
- |[] -> count
- printfn "exc.13 : %A" (count_less [2;3;7;11;4;9] 5 0)
- //14-
- let less_n list n = list |> List.filter(fun x-> x>=n) |> List.length
- printfn "ex.14 : %A" (less_n [2;3;7;11;4;9] 5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement