# Is there a sorting program or formula to sort and place individuals in classes based on preferences

I am looking for a formula or program to help place people in classes based on their preferences.

The elements of the problem are:

There are 30 class choices a student can pick from.

There are 400 students that are asked to rank their top ten class preferences.

Each class (specialty subject, but a class by year or age, i.e. 2nd grade, 3rd grade) has a maximum number of 20 available seats.

Students then get placed into six of the classes based on their selections. Our goal is place as many students in as many of their top choices as possible.

Secondarily those 400 students could be broken down by grade as well and our secondary goal may be to also have as many students from the same grade in each class. But this secondary goal is less important.

Looking for any help to solve this problem.

• Since your goal only relates to the number of students who receive their top choice, it seems it only matters what each student ranks as their first preference, and their preferences #2,#3,#4,#5 don't matter. Is that correct? Have you correctly stated the objective function you are trying to maximize? If yes, I suggest removing any mention of "top five" and instead indicate that each student indicates their top choice. If not, can you please edit the question to state the problem more clearly and precisely?
– D.W.
Mar 26, 2023 at 19:09
• Apologies. Yes, I will rephrase the question. Kids get placed into six classes and they rank their top 10 preferred selections. Thanks for asking. Mar 27, 2023 at 20:14
• "as many of their top choices as possible" - Can you state more precisely the objective function you are trying to optimize? I find this vague/unclear.
– D.W.
Mar 27, 2023 at 21:13
• This seems impossible, you're trying to put 400 students into 6 classes each (2400 positions) but you have 30 classes each with 20 seats (600 positions). You can't program your way out of this one, as written. Mar 30, 2023 at 4:08