fork download
  1. module CompanyContracts =
  2. type employee =
  3. | Manager of int
  4. | Marketolog of int
  5. | Engineer of int
  6. | Analist of int
  7. | Boss of employee
  8.  
  9. member private emp.Compute (manVal, marVal, engVal, anaVal, bosVal, ?growth) =
  10. let defaultGrowth xVal rank = int ((float rank-1.0)*0.25*float xVal)
  11. let growth = Option.fold (fun _ g -> g) defaultGrowth growth
  12. match emp with
  13. | Manager rank -> manVal + growth manVal rank
  14. | Marketolog rank -> marVal + growth marVal rank
  15. | Engineer rank -> engVal + growth engVal rank
  16. | Analist rank -> anaVal + growth anaVal rank
  17. | Boss emp
  18. -> int (bosVal*float (emp.Compute (manVal, marVal, engVal, anaVal, bosVal, growth)))
  19.  
  20. member emp.Tugriki = emp.Compute (500, 400, 200, 800, 1.5)
  21. member emp.Koffee = emp.Compute (20, 15, 5, 50, 2.0)
  22. member emp.Pages = emp.Compute (200, 150, 50, 5, 0.0, fun _ _ -> 0)
  23.  
  24. static member (*) (n : int, emp : employee) = List.replicate n emp
  25.  
  26. let me = Manager
  27. let ma = Marketolog
  28. let en = Engineer
  29. let an = Analist
  30.  
  31. type department =
  32. | Buys of employee list
  33. | Sales of employee list
  34. | Marketing of employee list
  35. | Logistics of employee list
  36.  
  37. member dept.Employees =
  38. match dept with
  39. | Buys emps | Sales emps | Marketing emps | Logistics emps -> emps
  40.  
  41. member dept.Name = ((sprintf "%A" dept).Split [| ' ' |]).[0].Trim() // yolo
  42.  
  43. type company =
  44. | Company of string * department list
  45.  
  46. member corp.Name =
  47. match corp with Company (name, _) -> name
  48. member corp.Departments =
  49. match corp with Company (_, depts) -> depts
  50.  
  51.  
  52. module DepartmentStats =
  53. open CompanyContracts
  54.  
  55. let inline private compute f (dept : department) =
  56. dept.Employees
  57. |> List.map f
  58. |> List.sum
  59.  
  60. let computeEmployeeCount = compute (fun emp -> 1)
  61. let computeEmployeeTotalWage = compute (fun emp -> emp.Tugriki)
  62. let computeEmployeeTotalKoffee = compute (fun emp -> emp.Koffee)
  63. let computeEmployeeTotalPages = compute (fun emp -> emp.Pages)
  64.  
  65.  
  66. module Bekmop =
  67. open CompanyContracts
  68.  
  69. let buysDept = Buys <| List.concat [ 9*me 1; 3*me 2; 2*me 3; 2*ma 1; [Boss (en 2)]]
  70. let salesDept = Sales <| List.concat [12*me 1; 6*ma 1; 3*an 1; 2*an 2; [Boss (me 2)]]
  71. let marketingDept = Marketing <| List.concat [15*ma 1; 10*ma 2; 8*me 1; 2*en 1; [Boss (me 3)]]
  72. let logisticsDept = Logistics <| List.concat [13*me 1; 5*me 2; 5*en 1; [Boss (me 1)]]
  73.  
  74. let departments = [buysDept; salesDept; marketingDept; logisticsDept]
  75.  
  76. let Bekmop = Company ("BEKTOP", departments)
  77.  
  78.  
  79. module Manya =
  80. open Bekmop
  81. open DepartmentStats
  82.  
  83. [<EntryPoint>]
  84. let manya _ =
  85. let puts s = printf "%s" <| (s : string).PadRight(10).Substring(0, 10)
  86. let putx x = puts <| x.ToString()
  87.  
  88. List.iter puts ["dept"; "sotr."; "tugr."; "kofe"; "str."; "tugr./str."]
  89. printfn ""
  90.  
  91. let stats =
  92. [ computeEmployeeCount
  93. computeEmployeeTotalWage
  94. computeEmployeeTotalKoffee
  95. computeEmployeeTotalPages ]
  96.  
  97. let baseStats =
  98. Bekmop.Departments
  99. |> List.map (fun d -> d.Name, List.map ((|>) d) stats)
  100. let totals =
  101. List.map snd baseStats
  102. |> List.fold (List.map2 (+)) (List.replicate stats.Length 0)
  103. let averages = List.map (fun total -> int <| float total / float stats.Length) totals
  104.  
  105. baseStats
  106. |> List.iteri (fun i (dName, stats) ->
  107. puts dName
  108. List.iter putx stats
  109. putx (float stats.[1] / float stats.[3]) //
  110. printfn "")
  111.  
  112. puts "Averages"
  113. List.iter putx averages
  114. printfn ""
  115. puts "Totals"
  116. List.iter putx totals
  117.  
  118. 666*0*1488
Success #stdin #stdout 0.28s 26760KB
stdin
Standard input is empty
stdout
dept      sotr.     tugr.     kofe      str.      tugr./str.
Buys      17        9050      357       3100      2.91935483
Sales     24        13737     654       3325      4.13142857
Marketing 36        16525     635       5450      3.03211009
Logistics 24        11375     450       3850      2.95454545
Averages  25        12671     524       3931      
Totals    101       50687     2096      15725