Advertisement
kiraventom

Untitled

Dec 19th, 2021 (edited)
928
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. const int MaxEntriesInBook = 200;
  2. var employees = Enumerable.Range(0, 601).ToList();
  3. double d_empCount = (double)employees.Count;
  4. List<Book> books = new();
  5. int booksAmount = (int)Math.Ceiling(d_empCount / MaxEntriesInBook);
  6.  
  7. int employeeIndex = 0;
  8. for (int i = 0; i < booksAmount; i++)
  9. {
  10.     double employeesPerBook = Math.Ceiling(d_empCount / booksAmount);
  11.    
  12.     int employeesToTakeAmount =
  13.         employees.Count - employeeIndex > MaxEntriesInBook
  14.         ? (int)employeesPerBook
  15.         : employees.Count - employeeIndex;
  16.        
  17.     var employeesToTake = employees.GetRange(employeeIndex, employeesToTakeAmount);
  18.     books.Add(new Book() {Employees = employeesToTake});
  19.     employeeIndex += employeesToTakeAmount;
  20. }
  21.  
  22. books.Select(b => b.Employees.Count).Dump();
  23. books.Sum(b => b.Employees.Count).Dump();
  24.  
  25. class Book
  26. {
  27.     public List<int> Employees { get; set; } = new();
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement