def Cactus(): size = get_world_size() init_plant(size, Entities.Cactus) goto((0,0)) field = [] for y in range(size): row = [] for x in range(size): goto((x,y)) better_plant(Entities.Cactus) row.append(measure()) field.append(row) for y in range(size): curr = field[y] while not is_sorted(curr): for x in range(size): goto((x,y)) if measure(East) < measure(): swap(East) if measure(North) < measure(): swap(North) for x in range(size): goto((x,y)) curr[x] = measure() for i in range(len(field)-1, 0, -1): quick_print(field[i], is_sorted(field[i])) while num_items(Items.Cactus) < 3000: harvest() Cactus() def diag_sort(mat): lst = [] n, m = len(mat), len(mat[0]) # leftmost column for i in range(n): lst.append([i, 0]) # rightmost row for i in range(m): lst.append([0, i]) lst.pop(0) for el in lst: i, j = el[0], el[1] arr = [] # getting the diagonal elements while i < n and j < m: arr.append(mat[i][j]) i, j = i+1, j+1 arr = insertion_sort(arr) i, j = el[0], el[1] # setting the element in sorted order while i < n and j < m: mat[i][j] = arr.pop(0) i, j = i+1, j+1 new = [] for y in range(len(mat)): arr = [] for x in range(len(mat)): arr.append(mat[x][y]) new.append(insertion_sort(arr)) quick_print("") for el in new: quick_print(el) return mat m1 = [ [4,5,6], [9,8,7], [2,3,1] ] for el in m1: quick_print(el) m1 = diag_sort(m1) quick_print("") for el in m1: quick_print(el)