vendredi 8 mai 2020

Python: how to distribute X instances to y lists randomly and avoid void lists

I'm trying to distribute Objects multiple references into various lists, following some rule.

Figure out this practical example. There are 6 kids, each one owning 4 cards with their name written on. They should put randomly each card into one of the 7 weekday slots (the target lists). So, for example, Mark can randomly put a card into Monday, one into Tuesday, one into Friday and one into Sunday. Jill put one of his cards into Monday, one into Thursday, one into Saturday and one into Sunday. In the end, all weekday slots must contain at least one card, if possibly so (as for "possibly so" I mean if there are enough kids and cards to accomplish this rule).

I'm positive about some inverse logic as long as the ending result (random distribuition and no void list if possibly so) is accomplished.




Aucun commentaire:

Enregistrer un commentaire