Untitled
unknown
python
2 years ago
1.3 kB
9
Indexable
def read_matrices_from_file(filename):
matrices = []
with open(filename, 'r') as file:
lines = file.readlines()
num_matrices = int(lines[0].strip())
lines = lines[1:]
for _ in range(num_matrices):
if lines[0].strip(): # Boş olmayan bir satırsa devam et
dimensions = lines[0].split()
rows = int(dimensions[0])
cols = int(dimensions[1])
lines = lines[1:]
matrix = []
for _ in range(rows):
row = list(map(int, lines[0].split()))
matrix.append(row)
lines = lines[1:]
matrices.append(matrix)
else: # Boş bir satırsa geç
lines = lines[1:]
return matrices
def create_sxor_functions(matrix):
rows = len(matrix)
cols = len(matrix[0])
sxor_functions = []
for i in range(rows):
sxor_function = "y{} = ".format(i + 1)
for j in range(cols):
if matrix[i][j] == 1:
sxor_function += "x{} + ".format(j)
sxor_function = sxor_function.rstrip(" + ")
sxor_functions.append(sxor_function)
return sxor_functionsEditor is loading...