Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let obwod a b=a+2*b
- obwod 1 2
- let pole_trojkata (a:float) (b:float)= 0.5*a*b
- pole_trojkata 1.0 2.0
- //zad2
- let x=3
- let rec suma_mnozenia a =
- if a < 1 then 0
- else x + suma_mnozenia (a - 1)
- suma_mnozenia 4
- //zad 3
- let x=2
- let rec mnozenie_mnozenia a =
- if a < 1 then 1
- else x * mnozenie_mnozenia (a - 1)
- mnozenie_mnozenia 3
- //zad4
- 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)
- //zad5
- 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] )
- //zad6
- 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)
- //zad7
- 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)
- //zad 8
- type Ksiazka={
- Tytul : string
- Autor : string
- Rok_wydania : int
- Wydawnictwo : string
- liczba_stron : int
- Twarda_oprawa : bool
- Miekka_oprawa : 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])
- //zad10
- 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