You might be interested in reading the Monad article on combinatorial sigfpe blog searches.
It defines a new monad, called a punishment list or PList, similar to the list monad, but which also has the concept of a penalty for more complex decisions. When you combine PLists, the order in which the results are created is the smallest penalty of the order β the largest penalty.
In your example, the penalty associated with an integer may be equal to the size of an integer, and the penalty associated with a tuple is the sum of the penalties of its elements. Thus, the tuple (3,4,5) has a penalty of 3 + 4 + 5 = 12, and the tuple (5,12,13) has a penalty of 5 + 12 + 13 = 30.
In the monad list, the order of the resulting tuples
(1,1,1), (1,1,2), (1,1,3), (1,1,4), (1,1,5) ...
and you will never see a tuple not shaped (1,1,x) . With monad PList, the resulting tuples can be
(1,1,1), (1,1,2), (1,2,1), (2,1,1), (1,1,3), (1,3,1), (3,1,1), (1,2,2) ...
with all the "smaller" tuples created before the "big" ones.
For your specific problem, this solution is redundant, but it can be very useful in more complex problems.