Untitled

mail@pastecode.io avatar
unknown
python
17 days ago
2.2 kB
0
Indexable
Never
import random
def create_array(i = 0):
	array = [0]*4;
	return create_array_recursive(array, i);

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_matriz(i = 0, j = 0):
	matriz = [[0,0,0],[0,0,0],[0,0,0]];
	return create_matriz_recursive(matriz, i, j);

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

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

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

def check_score_recursive(matriz, counter, aux, array, auxM):
	count = 0;
	count_corners = 0;
	if(matriz[1][0] + matriz[1][1] + matriz[1][2] > 10):
		count += 2;
	if(matriz[0][0] + matriz[0][1] + matriz[0][2] > 10):
		count += 2;
	if(matriz[1][1] >= (matriz[0][0] + matriz[0][2] + matriz[2][0] + matriz[2][2]) / 4 - 1 and matriz[1][1] <= (matriz[0][0] + matriz[0][2] + matriz[2][0] + matriz[2][2]) / 4 + 1):
		count += 3;
	if(matriz[1][1] < matriz[0][0]):
		count_corners += 1;
	if(matriz[1][1] < matriz[0][2]):
		count_corners += 1;
	if(matriz[1][1] < matriz[2][0]):
		count_corners += 1;
	if(matriz[1][1] < matriz[2][2]):
		count_corners += 1;
	if(count_corners == 2):
		count -=2;
	if(matriz[1][1] > matriz[0][0] and matriz[1][1] > matriz[0][2] and matriz[1][1] > matriz[2][0] and matriz[1][1] > matriz[2][2]):
		count -= 3;
	print_matriz(matriz, 0);
	print("count " + str(count));
	if(count > aux or counter == 0):
		aux = count;
		auxM = matriz;
	if(counter == 4):
		print("the biggest score is: " + str(aux));
		print("it matriz is: ");
		print_matriz(auxM, 0);
		return aux, auxM;
	matriz[1][1] = array[counter]
	return check_score_recursive(matriz, counter + 1, aux, array, auxM);




check_score();
Leave a Comment