1
$\begingroup$

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.

$\endgroup$
5
  • $\begingroup$ I don't really understand your problem. Which is the intended input and output of your algorithm? $\endgroup$
    – JnxF
    Commented Aug 14, 2019 at 0:05
  • $\begingroup$ 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. $\endgroup$
    – parnas
    Commented Aug 14, 2019 at 10:17
  • $\begingroup$ Added a more detailed example. $\endgroup$
    – parnas
    Commented Aug 14, 2019 at 10:23
  • $\begingroup$ This sounds like a constraint satisfaction problem (CSP). Take a look on that. $\endgroup$
    – JnxF
    Commented Aug 14, 2019 at 12:48
  • $\begingroup$ @JnxF Ah-ha! Thank you. Checking. $\endgroup$
    – parnas
    Commented Aug 14, 2019 at 15:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.