Untitled

mail@pastecode.io avatar
unknown
python
2 months ago
2.3 kB
3
Indexable
Never
import random
import copy;

def create_array():
	array = [0]*4;
	return create_array_recursive(array, 0);

def create_array_recursive(array, i):
	if(i > len(array) - 1):
		return array;
	array[i] = random.randint(-5,5);
	return create_array_recursive(array, i + 1);

def create_matrix():
	matrix = [[0,0,0],[0,0,0],[0,0,0]];
	return create_matrix_recursive(matrix, 0, 0);

def create_matrix_recursive(matrix, i, j):
	if(i > 2):
		return matrix;
	matrix[i][j] = random.randint(-5,5);
	if(j == 2):
		return create_matrix_recursive(matrix, i + 1, 0);
	else:
		return create_matrix_recursive(matrix, i, j + 1);

def print_matrix(matrix, i = 0):
	if(i > 2):
		return;
	print(str(matrix[i][0]) + 2*"\t" + str(matrix[i][1]) + 2*"\t" + str(matrix[i][2]));
	print_matrix(matrix, i + 1);

def check_score():
	matrix = create_matrix();
	array = create_array();
	auxM = [["","",""],["","",""],["","",""]];
	check_score_recursive(matrix, 0, 0, array, auxM, 0);

def check_score_recursive(matrix, counter, aux, array, auxM, count_draws):
	if(counter == 5):
		return final_print(aux, auxM);
	if(counter > 0):
		matrix[1][1] = array[counter - 1];
	count = 0;
	count_corners = 0;
	if(matrix[1][0] + matrix[1][1] + matrix[1][2] > 10):
		count += 2;
	if(matrix[0][0] + matrix[0][1] + matrix[0][2] > 10):
		count += 2;
	if(matrix[1][1] >= (matrix[0][0] + matrix[0][2] + matrix[2][0] + matrix[2][2]) / 4 - 1 and matrix[1][1] <= (matrix[0][0] + matrix[0][2] + matrix[2][0] + matrix[2][2]) / 4 + 1):
		count += 3;
	if(matrix[1][1] < matrix[0][0]):
		count_corners += 1;
	if(matrix[1][1] < matrix[0][2]):
		count_corners += 1;
	if(matrix[1][1] < matrix[2][0]):
		count_corners += 1;
	if(matrix[1][1] < matrix[2][2]):
		count_corners += 1;
	if(count_corners == 2):
		count -=2;
	if(matrix[1][1] > matrix[0][0] and matrix[1][1] > matrix[0][2] and matrix[1][1] > matrix[2][0] and matrix[1][1] > matrix[2][2]):
		count -= 3;
	print_matrix(matrix, 0);
	print("count " + str(count));
	if(count >= aux or counter == 0):
		aux = count;
		auxM = copy.deepcopy(matrix);
	return check_score_recursive(matrix, counter + 1, aux, array, auxM, count_draws);

def final_print(aux, auxM):
	print("the biggest score is: " + str(aux));
	print("it matrix is: ");
	print_matrix(auxM);


check_score();
Leave a Comment