# Quota sampling participants

We need to select participants, based on the quotas provided. For example:

exactly 15 men exactly 15 women

exactly 10 young exactly 10 middle aged exactly 10 old

exactly 10 poor exactly 10 middle class exactly 10 rich

The total number of participants should be exactly 30.

## What algorithm should be used to do that?

Simpler, more detailed, example. Let's say that output quota is: 4 people: 2 women, 2 men, 2 old, 2 young.

Input set is:

Man Young
Man Young
Man Old
Woman Old
Woman Young


So the matching output set should be:

Man Young
Man Old
Woman Young
Woman Old


If we'll just start adding people to the output set one by one, skipping those, that would go over the quota, we'll end up with:

Man Young Man Young Woman Old

We'll have Man Old and Woman Young left, but none of those would match the quota.

• I don't really understand your problem. Which is the intended input and output of your algorithm?
– JnxF
Commented Aug 14, 2019 at 0:05
• Input is the array of people. Each human has gender and age. The output should be array of people, arranged by the quota provided in the question. Commented Aug 14, 2019 at 10:17
• Added a more detailed example. Commented Aug 14, 2019 at 10:23
• This sounds like a constraint satisfaction problem (CSP). Take a look on that.
– JnxF
Commented Aug 14, 2019 at 12:48
• @JnxF Ah-ha! Thank you. Checking. Commented Aug 14, 2019 at 15:33