I have this situation that I need to let users define decisions based on the number of given conditions. For example my program needs to automatically generate a matrix as below given that there are two conditions (IsMale and IsSmoker):
IsMale: YES YES NO NO
IsSmoker: YES NO YES NO
And the deicsion is defined by user, therefore any of the following can be valid:
IsMale: YES YES NO NO
IsSmoker: YES NO YES NO
Decision: T F T F
IsMale: YES YES NO NO
IsSmoker: YES NO YES NO
Decision: F F F F
IsMale: YES YES NO NO
IsSmoker: YES NO YES NO
Decision: T T T T
For each condition there can only be two states, True and False. So the total number of combinations are calculated as below:
no of possible states (S) to the power of no of conditions (C) S ^ C = total no of combinations
4 possibilities (2 ^ 2 = 4)
Condition A T T F F
Condition B T F T F
8 possibilities (2 ^ 3 = 8)
Condition A T T T T F F F F
Condition B T T F F T F T F
Condition C T F T F T T F F
Hope I have explained myself a bit better than the original question.
Updated: according to the answer given by Guffa. Below is the hand calculation of his algorithm to generate the different combinations.
4 possibilities (2^2=4)
index = 0, (right shift 0)
binary 8 4 2 1 Value
original 0 0 0 1 1
& 1 0 0 0 1 1 T
original 0 0 1 0 2
& 1 0 0 0 1 0 F
original 0 0 1 1 3
& 1 0 0 0 1 1 T
original 0 1 0 0 4
& 1 0 0 0 1 0 F
index = 1, (right shift 1)
binary 8 4 2 1 Value
original 0 0 0 1 1
shift 0 0 0 0 0
& 1 0 0 0 1 0 F
original 0 0 1 0 2
shift 0 0 0 1 1
& 1 0 0 0 1 1 T
original 0 0 1 1 3
shift 0 0 0 1 1
& 1 0 0 0 1 1 T
original 0 1 0 0 4
shift 0 0 1 0 2
& 1 0 0 0 1 0 F
combinations:
Condition 1: TFTF
Condition 2: FTTF