I need to sort the values according to the following problem:For every n, determine the triples (i,j,k) that satisfies i+j+k=n, then sort the triples (for every n) with respect to the value of the formula (4*i+5*j+4*k+1) in ascending order. Here is the rough pseudocode:for n in range(3,N+1):   for i in range(1,n-1):        for j in range(1,n-1):            for k in range(1,n-1):                 if(i+j+k)==n:                    [sort triples in ascending order wrt to the value of (4*i+5*j+4*k+1)]For now, I can only print the triples that satisfy i+j+k=n.Is there a way to do the sorting inside the n loop? Or should I store them in an array then bubble sort later?
Sorting array according to a formula
sorting
For this precise case, (4*i+5*j+4*k+1) = 4*n+j+1.  Since n is a constant you need to sort it by j.  Or just use j for your outer loop (after n).Also, you can compute k directly from i and jfor n in range(3,N+1):   for j in range(1,n-1):        for i in range(1,n-1):            k = (n-i-j)            if (1<=k && k<=n):                 [print triplet (i,j,k)]