Got a match?

From Esolang
Jump to navigation Jump to search

Got a match? is a trivial sorting algorithm invented by User:A.

Algorithm (in Natural language)

While the next modified state is different from the previous state:
    Search from right to left for a matching item that is equal to the leftmost item
    Put that leftmost item after this matching item
    Delete that leftmost item
If the end of the item list is less than the beginning of the item list:
    Reverse-cat the item list

Examples

321321
 213321
  133221
   332211
*HALT*