def count_structure(n, sty="S1"): pat = S[sty] rows = [] for i in pat: if i==1: rows.append([(0,) + ((1,)*(n-2)) + (0,)]) elif i==0: rows.append([(0,)*i + (1,) + (0,)*(n-i-2) + (1,) for i in range(1, n-i-1)]) else: rows.append([(0,)+l for l in product([0,1], repeat=n-1) if l.count(1) > 1 and l.count(0) < n-2]) ret = [] proditer = ([p1,p2,p3] for p1,p2,p3 in product(*rows) if p1!=p2 and p2!=p3 and p1!=p3) for M in ProgressBar(maxval=prod(map(len, rows)))(imap(matrix, proditer)): if not any(S in ret for S in row_orbit(M)): ret.append(M) return ret
def contains_configuration(lst, M): return any(S in lst for S in row_orbit(M))