Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to serially number the output ?

I want the output of the following code to be serially numbered as

(1)A combination is-------

(2)A combination is -------

(3)A combination is-------

and so on.

The code is :

# Write your matrix

H = matrix(2,2, [1, 1,1, -1])     

n = 2   # Enter the order of the matrix H 

V = GF(2)^(n^2)               

R1=V.list()[1:]                    
 #We are removing the all-zero list because not needed for our purpose

R2=R1[:-1]                          
 #We are removing the all-ones list because not needed for our purpose

A = []
for v in  R2:
    A.append(matrix(ZZ,n,n,v))          
 # Forming n by n matrices from  list in  R2. Contains all 0,1 matrices.                                               

B=[]
for a in A:                       
     b=-a                                           # Forming n by n matrices from A by taking their negative. Contains all 0,-1 matrices    
     B.append(b)

C = []
for a in A:
    C.append(a)
for b in B:
    C.append(b)         #Union of A and B

test_sum = 4

test_comb = Combinations(C,test_sum)  
 # Here we are forming all "test_sum"-set combinations  from C".  
 # That is, if test_sum =3, then test_comb, gives all 3 set combinations  from C" 

for t in test_comb:
    if (sum(t)==H):                 
        #Checking which combinations in  test_sum give the  sum = H and printing those

        print("A combination is: ")    
        show(t)                     
        print("\n")