Consider, just a test example, the following list of lists of positive integers ordered ascendingly
L := [[1,2,7,12],[3,4,5,6],[1,2,5,9]];
I would like this list of lists ordered so that [1,2,5,9] precedes [1,2,7,12], because 5 < 7 (the first two elements being equal), and [1,2,7,12] precedes [3,4,5,6], because 1 < 3. I think you see the general scheme. That can be achieved with the following code:
with(ListTools):
swapLists := proc(L1::'list'(posint),L2::'list'(posint))
   local L;
   L := MakeUnique(L1-L2);
   if L = [0] then
      false
   elif L[1] <> 0 then
      L[1] < 0
   else
      L[2] < 0
   end if
end proc:
sort(L,swapLists);
My question is: does there exist some smarter way?

Please Wait...