In a village, there are 400 streets, 200 with yellow painted homes and 200 with blue painted homes. Each street has 16 homes as in the blueprint below.
But there are certain sets of rules that should be followed for accommodation in each home.
The Basic Rules for ideal conditions are:
Only one person can be accommodated in a home until all 16 homes on a street are filled by 16 people (one in each); only then can a home be shared by another person.
For a single street, a home is allocated to a person in increasing order, which means that first person arriving on a street would be accommodated in the first home, the second person in the second home, and so on.
Above accommodation rules are independent for each street, which means that streets can be allocated to any person randomly, but he/she would be accommodated in the home as per the above rules. (For example, if a person has been allocated to street 5, and if the first two homes on street 5 are already accommodated then he/she would be accommodated to home #3 of street #5, regardless of whether streets 1 to 4 are empty.)
Now the question is why are streets segregated in two different colors? The reason is that both have a unique set of accommodation rules based on Gender and Age.
Yellow Streets: They reserve homes based on two parameters. First, there is a max of 2 homes reserved for senior citizen (SC) per street. Second, after SC reservation, the remaining homes could be allocated to either male or female. Let's name these two parameters as SC and Mix.
Blue streets: They reserve homes based on three parameters. First, there is a max of 2 homes reserved for SC. This is the same as for yellow streets; the difference is in the remaining homes. Second, a few homes are reserved for females. Third, the remaining homes are reserved for males. Let's say name these three parameters as SC, F and M.
Now who will decide the values of these parameters?
The owner of this village has randomly set the parameters for each street as explained below, and homes should be allocated based on these parameters.
The ideal values of these parameters are:
For yellow, SC=2 and Mix=14, i.e., 2 homes (#15 and #16) are reserved for senior citizens and yhr remaining 14 homes (#1 to #14) are for either males or females.
For blue, SC=2, F=7 and M=7, i.e., 2 homes (#15 and #16) are reserved for SC, 7 homes (#8 to #14) are reserved for females and the remaining 7 (#1 to #7) are reserved for males.
However, the value of these parameters for each street is different and the summation of these parameters would never be more than 16 and less than 1. For example, for a yellow street, the parameters could be "SC=0, Mix=16" or "SC=1, Mix=15" or "SC=2, Mix=0" or anything else. For a blue street, the parameters could be "SC=1, F=1 and M=3", "SC=0, F=1 and M=0", or any other combination.
Suppose for a yellow street the combination is "SC=1 and Mix=3", then a male or female can be accommodated in any home from #1 to #3 and SC can be accommodated in home #16 only. And the remaining homes (#4 to #15) are locked and no one can use those homes. For blue homes, the rules are applied in same manner, just Mix is further categorized in M and F.
Max possible value for each parameter: In case of blue and yellow streets, the max possible value for SC is 2. And for all the other categories, the maximum possible value is 16.
Special case of SC, if SC=2, then the reserved homes for SC are #15 and #16. If SC=1, then the reserved home is #16 and if SC=0, then there isn't any home reserved for SC on that particular street.
In case of Mix, the reservation of homes would always start from #1 and till the assigned value of Mix. For example, if Mix=15, then #1 to #15 are reserved for Mix.
In case of M, the reservation of homes would start from #1 and till the assigned value of M.
In case of F, the reservation of homes would start from the home number after the last home number of M. For example, if F=13 and M=3, then homes #4 to #16 are reserved for females. and if M=0 and F=2, then homes #1 and #2 are reserved for Females.
Repetition Rule: this is the same rule, as mentioned in basic rules, but more detailed. For a given street with set parameters, the allocation of homes can not be repeated until the reserved home for the same category (or parameter) is filled once. Let's say for Blue Street #2, the parameters are set as SC=1, M=2 and F=3. If the first person to arrive is SC, then he/she would be accommodated at home #16. If the second is Male, then he would be accommodated at # 1, if the 3rd person is again SC, then he/she has to share home #16 with first person. If the 4th is Female, she would be accommodated at #3, and so on.
Now you are appointed as the supervisor of this village and as a supervisor, you have to make sure that none of the above rules are broken, and for that you have one logical-magical stick. If someone breaks a rule, then you can kick him/her out and also charge them 500 bucks. But if you fail to prevent anyone from breaking these rules then owner of this village will fire you and will charge you 10,000,000,000,000 bucks. ;-)
What logic would you apply to that logical-magical stick, so that you can make sure that the accommodation is always aligned with the rules?
Supervisor has record of all the arriving persons, their age, gender, street to be allocated including blue/yellow homes and value of parameters (SC, Mix, M, F) for each streets.