Algorithm to schedule employees into days

I’m trying to build a scheduling app for a friend, but am stuck on how to sort the employees.

I have three holidays each with their own employee_need:

thanks_giving: 2

christmas: 3

new_years_eve: 2

I have employees who have a predetermined number of days they will work. The sum of the employee’s predetermined work days will always add up to the sum of the three holiday’s employee_need. They also have ranked the holidays by preference, which should guide the scheduling process.
The data looks something like this:


days_to_work: 1

preferences: [christmas, new_years_eve, thanks_giving]


days_to_work: 2

preferences: [thanks_giving, christmas, new_years_eve]


Right now my process of sorting is to

  1. Fill each holiday with a list of all employees.

  2. Loop through the employees, starting with those who have the most days off.

  3. Loop through the employee’s preferences and pull them from the one they most desire to have off that also has room for them to be taken off

  4. Continue looping until the days are properly scheduled. If there is room to remove them from that day, I do so, until they are working the number of days they are supposed to.

The algorithm works a decent amount of time, but I really need it to work all the time.

Is anyone familiar with this kind of problem, and can point me toward a better methodology?