This is a combinatorial problem encountered in calculating the relative occurrence of certain outputs produced by an algorithm based loosely on genetics, in order to predict the probability that a certain outcome will take place.
We are faced with an ordered set S of N sets of 4 arbitrarily chosen bits. Example for N = 2: S = {{1,1,1,0}, {1,0,0,0}}
We wish to determine the number of ways K to produce a binary number containing exactly n 1-bits by selecting one bit from each set, where the ith bit is taken from the ith set. Example for N = 2: Given S = {{1,1,1,0}, {1,0,0,0}}, there are ten ways to form a binary number containing exactly one 1-bit: 10 has nine possibilities, and 01 has one possibility.
The general problem can be solved by brute force, simply iterating over all possibilities and counting them. However, we would like to perform these calculations for reasonably large numbers N and n, and would therefore like to find a general solution that is not computationally heavy, if it exists.
It stands to reason that a solution, if it exists, should depend on N and n, as well as the numbers $k_j$ of sets in S with j 1-bits ($j = 0,...,4$). My gut tells me that K probably follows some nice distribution (binomial, perhaps) between the extremes (i.e. selecting only ones from sets of all ones, or selecting only zeros sets of only zeros).
If there is no general solution, then an approximative method would also be of interest.
Edit: A more intuitive way to describe the problem would be this:
Suppose you have N bags, each of which contains 4 tiles with a letter on it. You are tasked with building words of length N by taking one tile from each bag. Moreover
- The only letters that may exist in the bags are A and B.
- You must build a word that contains exactly n instances of the letter A.
- You must always pick letters from the bags in the same order (the bags are numbered).
- The number of As and Bs in each bag is arbitrary, but known.
How many such words can you form?