Untitled

mail@pastecode.io avatar
unknown
python
a month ago
5.6 kB
4
Indexable
Never
import random;

matriz =[[" "," "," "," "," "],[" "," "," "," "," "],[" "," "," "," "," "],[" "," "," "," "," "],[" "," "," "," "," "]]

array =["","","","",""]

def print_matriz(k):
	print("------------------");
	aux = "";
	i = 0;
	for i in range(k):
		j = 0;
		while(j < len(matriz)):
			aux = aux + str(matriz[i][j]) + "\t";
			j = j + 1;		
		print(aux);
		aux = "";
	print("------------------");

def print_array():
	aux = "";
	i = 0;
	while(i < len(array)):
		aux = aux + str(array[i]) + "\t";
		i = i + 1;
	print(aux);

def numbers():
	global array;
	print("you have to choose the minimun and maximum for filling up a square");
	aux2 = False;
	while(aux2 == False):
		aux = False;
		aux1 = False;
		while(aux == False):
			min = input("which number do you want to be the minimum? ");
			try:
				int(min);
				min = int(min);
				aux = True;
			except:
				print("a number please");
		while(aux1 == False):
			max = input("which number do you want to be the maximum? ");
			try:
				int(max);
				max = int(max);
				aux1 = True;
			except:
				print("a number please");
		if(max - min < 0):
			print("maximum must be bigger than minimum");
			aux2 = False;
		else:
			aux2 = True;
	place_numbers(min,max);
	biggest_recursive(auxiliary,0,1,0);
	print("the column/s with biggest addition is/are: ")
	print_result_column(0);
	print("it add is: ")
	print_result_add(0);
	new_row(min,max);
	print("extra row: ");
	print_array();
	middle_order_extra_row(0, 1);
	order_rows(0,1);
	copy_array = array;
	array = ["","","","",""];
	final_order_extra_row(0, copy_array);
	print("the correct order of the extra row is: ")
	print_array();

def place_numbers(min,max):
	count1 = 0;
	i = 0;
	while(i < len(matriz)):
		j = 0;
		while(j < len(matriz)):
			matriz[i][j] = random.randint(min,max);
			j = j + 1;
		count1 = count1 + 1;
		print_matriz(count1);
		addition(count);
		i = i + 1;

def new_row(min,max):
	i = 0;
	while(i < len(array)):
		array[i] = random.randint(min,max);
		i = i + 1;

auxiliary = [0,0,0,0,0];
count = 0;
def addition(i,j=0):
	addition_recursive(i,j);
	biggest_recursive(auxiliary,0,1,0);
	if(i < 4):
		print("until now the biggest column/s is/are:");
		print_result_column(0);
		print("until now the biggest add is: ");
		print_result_add(0);
		i = 0;
		for i in range(5):
			print("\n");

def addition_recursive(i,j):
	global auxiliary;	
	global count;
	if(j == len(matriz)):
		count = count + 1;
		return;
	try:
		if(j == 0):
			auxiliary[0] = auxiliary[0] + matriz[i][j];		
		elif(j == 1):
			auxiliary[1] = auxiliary[1] + matriz[i][j];
		elif(j == 2):
			auxiliary[2] = auxiliary[2] + matriz[i][j];
		elif(j == 3):
			auxiliary[3] = auxiliary[3] + matriz[i][j];
		elif(j == 4):
			auxiliary[4] = auxiliary[4] + matriz[i][j];
		addition_recursive(i, j + 1);
	except:
		return;

auxiliary1 = ["","","","",""];
auxiliary2= ["","","","",""];

def biggest_recursive(array, position, comparable, counter):
	global auxiliary1;
	global auxiliary2;
	if(position + comparable == len(array)):
		return;
	if(array[position] < array[position + comparable]):
		auxiliary1 = ["","","","",""];
		auxiliary1[0] = str(position + comparable);
		auxiliary2 = ["","","","",""]
		auxiliary2[0] = array[position + comparable];
		biggest_recursive(array, position + comparable, 1, 1);
	elif(array[position] > array[position + comparable]):
		auxiliary1[0] = str(position);
		auxiliary2[0] = array[position];
		biggest_recursive(array, position, comparable + 1, 1);
	else:
		if(counter == 0):
			auxiliary1[0] = str(position);
			auxiliary2[0] = array[position];
			counter = counter + 1
		auxiliary1[counter] = str(position + comparable);
		auxiliary2[counter] = array[position + comparable];
		biggest_recursive(array, position, comparable + 1, counter + 1);

def print_result_column(position):
	if(position == len(auxiliary1)):
		return;	
	try:
		int(auxiliary1[position]);
		print(int(auxiliary1[position]) + 1);

		print_result_column(position + 1);
	except:
		return;

def print_result_add(position):
	int(auxiliary2[position]);
	print(auxiliary2[position]);

def middle_order_extra_row(position, comparable):
	aux = 0;
	if(position + comparable == len(array)):
		return;
	if(array[position] < array[position + comparable]):
		aux = array[position];
		array[position] = array[position + comparable];
		array[position + comparable] = aux;
	if(position + comparable < len(array) - 1):
		middle_order_extra_row(position, comparable + 1);
	else:
		middle_order_extra_row(position + 1, 1);

auxiliary3 = [0,1,2,3,4];

def order_rows(position, comparable):
	global auxiliary;
	global auxialiary3;
	aux = 0;
	aux1 = 0;
	if(position + comparable == len(auxiliary)):
		return;
	if(auxiliary[position] > auxiliary[position + comparable]):
		aux = auxiliary[position];
		auxiliary[position] = auxiliary[position + comparable];
		auxiliary[position + comparable] = aux;
		aux1 = auxiliary3[position];
		auxiliary3[position] = auxiliary3[position + comparable];
		auxiliary3[position + comparable] = aux1;
	if(position + comparable < len(auxiliary) - 1):
		order_rows(position, comparable + 1);
	else:
		order_rows(position + 1, 1);


def final_order_extra_row(position, copy_array):
	global array;
	if(position == len(array)):
		return;
	array[auxiliary3[position]] = copy_array[position]; 
	final_order_extra_row(position + 1, copy_array);
numbers();
Leave a Comment