0

Somehow I can't think of the solution which is probably simple once mentioned.

So I need to make a program where I need to divide in equal parts.

given:

  • 5 types of classes (say mechanics, it, management etc)
  • 400 students
  • each class can contain a max of 32 students

Now I need to equally divide the 400 students over those classes. So that would mean 400 / 5 = 80 per type of class

So 80 students for mechanics for example divided in equal groups as much as possible so 3 groups of 27 - 27 - 26 students.

The number of students can differ so it needs to calculate that automatically.

another example: 200 students / 5 is 40 so 1 type of class has 2 groups of 20 students..

If someone can explain me that in pseudocode I would be thankfull!

DaViDa
  • 641
  • 1
  • 8
  • 28
  • Show us your attempt at it. – Evan LaHurd Oct 08 '15 at 18:55
  • The attempt I had was to fill all those groups up to 32 a group until the number of students of that type of class was met, but that can lead to a group of only 2 students in the end, not really ideal. I just can't come up with the logic for it somehow – DaViDa Oct 08 '15 at 18:59
  • 1
    Do it the other way around, spread the students over the classes. One student in mechanics, one in it, one in mangement and so on as long as you have classes. Then start over, another student in mechanics... Continue as long as you have students or the class is filled up. – Kennet Oct 08 '15 at 19:38

0 Answers0