Dropsort

From Esolang
Jump to navigation Jump to search

Dropsort is a highly efficient, one-pass esoteric algorithm for sorting that always returns a properly sorted list.

Description

Dropsort goes through the list dropping items from the list that are out of place. This may seem undesirable, but the reader is urged to remember that lossy algorithms like this are well-accepted in computer science; for example, the JPEG algorithm.

Algorithmic description

(In this description, list indices start at 1.)

  • For each item x in the range from 2 to the length of the list
    • If item x of the list is less than item x-1 on the list
      • Drop item x from the list
  • Return the list