1 | initial version |
This draft code may also be seen(though there are repetitions)
def add(l1,l2):
if len(l1)!=len(l2):
return('Error in lengths..!')
new = []
for ee in range(len(l1)):
#print(vector(l1[ee]))
new.append(list(vector(l1[ee])+vector(l2[ee])))
return new
def mat_set(l1):
temp = []
for a in (l1):
temp.append(matrix(m , m, a))
return temp
def add_n(a):
test = []
mat_A = [[0]*(len(M_list))]*n
mat_A = matrix(mat_A)
d = 0
while d<len(M_list):
mat_A += matrix(main[d][a[d]])
d=d+1
return list(mat_A)
def test_1_m1(com):
for a in com:
cc=0
cd=0
for ai in a:
if ai==1:
cc=1
if ai==-1:
cd=1
if (cc==1 & cd ==1):
return 0
return 1
m = int(input("Enter the order m of your matrix (m x m):"))
print("Enter the elements of your matrix (size: "+str(m)+"x"+str(m)+") row wise")
temp = []
for i in range(m^2):
temp.append(int(input()))
M = matrix(m,m,temp)
show("M =",M)
temp = []
for i in range(M.nrows()-1):
temp +=list(vector(M[i:]))
M_list=temp
n = int(input("In how many matrices you want to break M:"))
T=Tuples((0,-1,1),n)
sum_1 = []
sum_m1 = []
for a in T:
if sum(a)==1:
sum_1.append(a)
if sum(a)==-1:
sum_m1.append(a)
temp_comb = []
for i in range(n):
temp_comb.append([0]*len(M_list))
main = []
for x in range(len(M_list)):
M_elem = x
main_temp = []
if M_list[M_elem]==1:
ss = sum_1
if M_list[M_elem]==-1:
ss = sum_m1
for w in range(len(ss)):
temp_comb = []
for i in range(n):
temp_comb.append([0]*len(M_list))
for j in range(n):
temp_comb[j][M_elem] = ss[w][j]
main_temp.append(temp_comb)
main.append(main_temp)
V = (Integers(len(sum_1)))^(len(M_list))
main_com = []
for a in V:
com = add_n(a)
if vector([0]*(len(M_list))) not in com:
if test_1_m1(com)==1:
main_com.append(com)
show(mat_set(com))