|
import csv |
|
import os |
|
import random |
|
|
|
def print_matrix(matrix): |
|
for row in matrix: |
|
print(','.join(map(str, row))) |
|
|
|
def generate_random_values(num_values): |
|
return [random.randint(0, 8) for _ in range(num_values)] |
|
|
|
def randomize_l1(matrix, random_values, identical_positions, combination_positions): |
|
for i in range(len(matrix)): |
|
if (i, i + 1) in identical_positions or (i + 1, i) in identical_positions: |
|
|
|
matrix[i][0] = random_values[i] |
|
matrix[i + 1][0] = random_values[i] |
|
elif (i, i) in combination_positions: |
|
|
|
matrix[i][0] = random_values[i] |
|
else: |
|
|
|
matrix[i][0] = random_values[0] |
|
|
|
|
|
def find_same_letter_positions(text): |
|
same_letter_positions = [] |
|
for i in range(len(text)): |
|
for j in range(i + 1, len(text)): |
|
if text[i] == text[j]: |
|
same_letter_positions.append((i, j)) |
|
same_letter_positions.append((j, i)) |
|
return same_letter_positions |
|
|
|
|
|
def find_combination_positions(text, combinations): |
|
combination_positions = [] |
|
for combination in combinations: |
|
i = 0 |
|
while i < len(text) - len(combination) + 1: |
|
if text[i:i+len(combination)] == combination: |
|
for j in range(i, i+len(combination)): |
|
combination_positions.append((j, j)) |
|
i += len(combination) |
|
else: |
|
i += 1 |
|
return combination_positions |
|
|
|
|
|
def create_matrix_from_text(text): |
|
num_rows = len(text) |
|
num_columns = num_rows |
|
|
|
|
|
matrix = [[0] * num_columns for _ in range(num_rows)] |
|
|
|
|
|
for i in range(num_rows): |
|
matrix[i][0] = text[i] |
|
|
|
return matrix |
|
|
|
|
|
for i in range(1, 20): |
|
csv_filename = f'text{i}.csv' |
|
combo_filename = f'text{i}combo1.csv' |
|
|
|
|
|
with open(csv_filename, 'r') as file: |
|
reader = csv.reader(file) |
|
text = next(reader)[0] |
|
|
|
|
|
same_letter_positions = find_same_letter_positions(text) |
|
print(f"\n{text} - Same Letter Positions:", same_letter_positions) |
|
|
|
|
|
combinations_to_find = ["bl", "wh", "sa", "wo", "no", "ve", "ab", "gro", "pu", "lo", "co", "bus", "pla", "ac", "at", "pr", "fa", "gr", "to", "or", "fa", "fr", "ki", "qu", "cl", "ok", "fig", "run", "ee", "BL", "WH", "SA", "WO", "NO", "VE", "AB", "GRO", "PU", "LO", "CO", "BUS", "PLA", "AC", "AT", "PR", "FA", "GR", "TO", "OR", "FA", "FR", "KI", "QU", "CL", "OK", "FIG", "RUN", "EE"] |
|
|
|
|
|
combination_positions = find_combination_positions(text, combinations_to_find) |
|
print(f"{text} - Combination Positions:", combination_positions) |
|
|
|
|
|
matrix = create_matrix_from_text(text) |
|
|
|
|
|
random_values = generate_random_values(len(text)) |
|
|
|
|
|
randomize_l1(matrix, random_values, same_letter_positions, combination_positions) |
|
|
|
|
|
print(f"{text} - Matrix After Randomization:") |
|
print_matrix(matrix) |
|
|
|
|
|
with open(combo_filename, 'w', newline='') as csvfile: |
|
writer = csv.writer(csvfile) |
|
for row in matrix: |
|
writer.writerow(row) |
|
|