python - Looking for an algorithm to count the number of possible patterns -
i need in constructing algorithm solve following problem:
a 5x5 table can filled values 0 , 1 each line , each column of table consists of 2 ones , 3 zeros. how many solutions exist?
if want provide code, can freely use preferred language. use r, matlab , python.
i tried convert table vector:
unique(perms([ones(1,10),zeros(1,15)]), 'rows')
then, each row, form 5x5 table , check if row sums , col sums equal 2. above command generated error: ??? maximum variable size allowed program exceeded.
here python expression bute forces matrices 2 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) ))
Comments
Post a Comment