Advertisement
slawekssj4

KOLOS SZARP F

Nov 19th, 2019
1,560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 2.76 KB | None | 0 0
  1. //1
  2. //a
  3. let tris_same_shoulders (a:float) (h:float)  =
  4.   let area = (a*h)/2.0
  5.   let circuit_xd =
  6.     let diag = sqrt ( (h*h) + (a/2.0)*(a/2.0))
  7.     2.0*diag + a
  8.   (area, circuit_xd)
  9. //b
  10. let six_corner (a:float) = (3.0* a*a *sqrt(a) )/2.0
  11. printf "exc.1-a %A" (tris_same_shoulders 4.0 2.0)
  12. printf "exc.1-b %A" (six_corner 2.0)
  13. //2--
  14. let rec x_n x n buff=
  15.   if n>0 then x_n x (n-1) (buff+x) else buff
  16. printf "exc.2 %A" (x_n 2 4 0)
  17.  
  18. //3-
  19. let rec x_M_n x n buff=
  20.   if n>0 then x_M_n x (n-1) buff*x else buff
  21. printf "exc.3 %A" (x_M_n 2 4 1)
  22.  
  23. //4-
  24. let rec e_s_l list bb =
  25.   match list with
  26.   | x::r -> (e_s_l r (x::rest) )
  27.   | [] -> rest
  28. printf "exc.4 %A" (e_s_l [1;2;3;4;5;6;7;8;9] [])
  29.  
  30. let rec e_s_l list buff bb =
  31.   match list with
  32.   | x::r -> if bb=true then (e_s_l r (x::buff) false) else (e_s_l r buff true)
  33.   | [] -> List.rev buff
  34. printf "exc.4 %A" (e_s_l [1;2;3;4;5;6;7;8;9] [] true)
  35.  
  36. //5-
  37. let rec_hr list =
  38.   let bb = true
  39.   list |> List.indexed|> List.filter(fun  (i, x)  -> i%2=0 ) |> List.map (fun (i, x) -> (x))
  40. printf "exc.5 %A" (rec_hr [1;2;3;4;5;6;7;8;9] )
  41.  
  42. //6-
  43. let rec filter_by_n list buff n =
  44.   match list with
  45.   | x::r -> if x%n=0 then (filter_by_n r (x::buff) n) else (filter_by_n r buff n)
  46.   | [] -> List.rev buff
  47. printf "exc.6 %A" (filter_by_n [1;2;3;4;5;6;7;8;9] [] 3)
  48.  
  49. //7-
  50. let rec_hr list n = List.filter(fun x -> x%n=0 ) list
  51. printf "exc.7 %A" (rec_hr [1;2;3;4;5;6;7;8;9] 3)
  52.  
  53. //8-
  54. type ksiazka = {
  55.   tytul : string;
  56.   autor : string;
  57.   data_wydania : string;
  58.   wydawnictwo : string;
  59.   lista_stron : int;
  60.   oprawka_twarda : bool;
  61. }
  62.  
  63. //9-
  64. let min_max_rec list =
  65.   let rec min list got =
  66.     match list with
  67.     | x::rest -> if x<got then min rest x else min rest got
  68.     | [] -> got
  69.   let rec max list got =
  70.     match list with
  71.     | x::rest -> if x>got then max rest x else max rest got
  72.     | [] -> got
  73.   (min list list.[0], max list list.[0])
  74. printfn "ex.9 %A" (min_max_rec [3;2;1;5;8;2])
  75.  
  76. //10-
  77. let min_max list = (List.min list, List.max list)
  78. printfn "ex.10 %A" (min_max [3;2;1;5;8;2])
  79.  
  80. //11-
  81. let average_rec list =
  82.   let rec sum list got=
  83.     match list with
  84.     |x::rest -> sum rest (x + got)
  85.     |[] -> got
  86.  
  87.   (sum list 0) / (List.length list)
  88.  
  89. //printfn "ex 11 %A" (average_rec [1;2;3;4])
  90.  
  91. //12-
  92. let average_high list =
  93.   let sum list = List.fold (+) 0 list
  94.   (float (sum list))/(float (List.length list))
  95. printfn "ex 12 %A" (average_high [1;2;3;4])
  96.  
  97. //13-
  98. let rec count_less list n count =
  99.   match list with
  100.   | x::rest ->if x<n then count_less rest n (count+1) else count_less rest n count
  101.   |[] -> count
  102. printfn "exc.13 : %A" (count_less [2;3;7;11;4;9] 5 0)
  103.  
  104. //14-
  105. let less_n list n = list |> List.filter(fun x-> x>=n) |> List.length
  106. printfn "ex.14 : %A" (less_n [2;3;7;11;4;9] 5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement