Looking for an algorithm to count the number of possible patterns
Question: I need your help in constructing an algorithm to solve the following problem:

`A 5x5 table can be filled with the values ​​0 and 1 so that each line and
each column of the table consists of exactly two ones and three zeros. How
many solutions exist?`

If you want to provide some code, you can freely use your preferred language.
I mostly use R, Matlab and Python.

I tried to convert the table into a vector:

    
    
    unique(perms([ones(1,10),zeros(1,15)]), 'rows')
    

Then, for each row, I would form the 5x5 table and check if all row sums and
col sums equal 2. But the above command generated the error: `??? Maximum
variable size allowed by the program is exceeded.`


Answer: Here is a python expression that bute forces all the matrices with two 1s per
row:

    
    
    from itertools import *
    print len(filter(
      lambda candidate: all(imap(
        lambda index: sum(imap(lambda _: _[index], candidate)) == 2,
        xrange(5)
      )),
      product(set(permutations([0,0,0,1,1])), repeat=5)
    ))
    

