-={Challenge}=- Ultimate Sorter
I was wondering if it was possible to use a recursive algorithm to group a list of integer lists (like a list of points, but with more than 3 reals) in order to sort them.
Where the priority is from left to right, car->cadr->caddr->..->last [see the expected result and you'll understand] :
(foo
'( ; a random messed up list of lists is given to be sorted:
(1 3 6 2)
(1 2 3 4)
(1 3 4 5)
(2 4 6 1 3)
(3 2 4 5 4)
(3 2 4 8 2)
(2 5 5 1 2)
(2 5 6 1 7)
(1 2 3 5)
)
)
>>
'( ; Priority, sort by the minimal (car) value, if there are other elements that are equal, then group and try sorting by (cadr), if some of them have equal, try (caddr)... and so on
(1 2 3 4) ; CAR = 1
(1 2 3 5) ; CAR = 1, the next ones are equal to the first, but the last one is above 4
(1 3 4 5) ; CAR = 1, but CADR = 3, thats why is 3rd (because the (cadr) of the first set is with value of 2)
(1 3 6 2) ; CAR = 1, and CADR = 3, but the 3rd element is higher than the previous item
(2 4 6 1 3) ; CAR = 2 .. compare CADRs, if there are equals, then compare CADDRs
(2 5 5 1 2)
(2 5 6 1 7)
(3 2 4 5 4) ; CAR-CADR have equals, compare CADDR
(3 2 4 8 2)
)
I've called this idea 'Ultimate Sorter', but no idea if such thing is already figured out and its way over my head.