mardi 20 octobre 2015

Distribute persons on days

I have 15 persons in an array

names = ["A", "B", "C", ...];

and the dates in a month, representing Monday, Tuesday, Wednesday, Thursday and Sunday

days = [1, 2, 3, 4, 7, 8 ..., 31];

I have to randomly distribute the persons at least 2 times in the month but there are some conditions.

Some of the persons have some preferences, saying which weekdays they prefer.

How can I store their preferences and how can I distribute the persons on all the days, so each day has a person?

I guess I have to loop through the days and randomly pick one of the persons, and before picking the person, I have to check if it is OK with his/her preferences.. If the person has been used two times, he/she should be deleted from the array, so he/she cannot be used again.

Is this a correct approach to the problem?




Aucun commentaire:

Enregistrer un commentaire