Possible Combinations with 2 variables and 4 columns

61 Views Asked by At

I have four columns: A, B, C, and D. In each column, it is possible to have: Yes or No. For instance, the first row might read: Yes, Yes, Yes, Yes across each of the four columns. The second row might read: No, No, No, No across each of the four columns and so on. The third row might read: Yes, No, Yes, No across each of the four columns.

What are all the possible combinations of Yes and No by column?

I tried a heuristic approach and found many of them but some elude me.

1

There are 1 best solutions below

0
greg spears On

Ouroborus in comments said it first: there are 16 combinations possible, manifesting in 16 rows.... and further... that 0 through 15 in binary will essentially yield what you want.

This table is the result of code I wrote ... runnable code is here. Specifically, the table is the result of translating a binary representation of numbers 0 through 15 into YES and NO:

#   A   B   C   D
-   -   -   -   -
1.  NO  NO  NO  NO
2.  NO  NO  NO  YES
3.  NO  NO  YES NO
4.  NO  NO  YES YES
5.  NO  YES NO  NO
6.  NO  YES NO  YES
7.  NO  YES YES NO
8.  NO  YES YES YES
9.  YES NO  NO  NO
10. YES NO  NO  YES
11. YES NO  YES NO
12. YES NO  YES YES
13. YES YES NO  NO
14. YES YES NO  YES
15. YES YES YES NO
16. YES YES YES YES

#include <stdio.h>

/* Binary representation of 0 through 15.  This two-dimensional
* character array nicely represents all the possibilities of 
* bit combinations of 4 bits in ones and zeroes 
* (or 4 columns of Yes and NO) */
char num[16][4] = {
"0000",
"0001",
"0010",
"0011",
"0100",
"0101",
"0110",
"0111",
"1000",
"1001",
"1010",
"1011",
"1100",
"1101",
"1110",
"1111"};

int main()
{
int yyy, xxx;

    /* In this section we will translate the array of ones and zeroes
    * into "YES" and "NO" respectively and print a table of same:  */

    printf("#\tA\tB\tC\tD\n");
    printf("-\t-\t-\t-\t-\n");
    
    for(yyy = 0; yyy < 16; yyy++)
    {
        printf("%d. ", yyy+1);
        for(xxx = 0 ; xxx < 4; xxx++)
        {
            if(num[yyy][xxx]== '1')
                printf("\tYES");
            else
                printf("\tNO");
        }
        putchar('\n');
    }
    return 0;
}