Distribution Algorithm for people with voting opportunities

Hello everyone, i have the following problem. I want to create an algorithm in Javascript that solves the following problem. At the moment I lack the solution.

There are 100 people and 100 boxes. Each person has three votes with ranking (first choice, second choice, third choice). With each voice, the person can choose a different box. For example, person A chooses box 55 with the first voice, box 1 with the second and box 10 with the third. Person B chooses box 45 with the first voice, box 55 with the second and box 5 with the third… It is not possible to choose the same box twice. A box can be selected by several people.

Javascript should assign exactly one box to each person. When distributing, the algorithm should take into account the desired boxes. The majority of people should get a box of their first or second choice, if it is possible. The algorithm should work fairly and fast. Does anyone know a name from an algorithm that solves the problem

Thanks in advance

If votes have weight, meaning the first choice wins over the second and the third, than it looks like Instant-runoff voting algorithm.

1 Like

Thank you for your answer. Yes the votes have weight. Is it possible with the algorithm that each person is assigned to a box (preferably the first choice if it is possible). Only one person can be assigned to a box. Can the algorithm distribute people so that most people are assigned to their primary election?