Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int MaxEntriesInBook = 200;
- var employees = Enumerable.Range(0, 601).ToList();
- double d_empCount = (double)employees.Count;
- List<Book> books = new();
- int booksAmount = (int)Math.Ceiling(d_empCount / MaxEntriesInBook);
- int employeeIndex = 0;
- for (int i = 0; i < booksAmount; i++)
- {
- double employeesPerBook = Math.Ceiling(d_empCount / booksAmount);
- int employeesToTakeAmount =
- employees.Count - employeeIndex > MaxEntriesInBook
- ? (int)employeesPerBook
- : employees.Count - employeeIndex;
- var employeesToTake = employees.GetRange(employeeIndex, employeesToTakeAmount);
- books.Add(new Book() {Employees = employeesToTake});
- employeeIndex += employeesToTakeAmount;
- }
- books.Select(b => b.Employees.Count).Dump();
- books.Sum(b => b.Employees.Count).Dump();
- class Book
- {
- public List<int> Employees { get; set; } = new();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement