Skip to content

Instantly share code, notes, and snippets.

@globby
Created March 6, 2014 00:22
Show Gist options
  • Save globby/9379637 to your computer and use it in GitHub Desktop.
Save globby/9379637 to your computer and use it in GitHub Desktop.
An implementation of the recursive Stoogesort algorithm
def stoogesort(lst):
def recurse(lst,i,l):
if lst[l] < lst[i]:
lst[i], lst[l] = lst[l], lst[i]
if (l - i + 1) >= 3:
t = (l - i + 1) / 3
recurse(lst, i, l-t)
recurse(lst, i+t, l)
recurse(lst, i, l-t)
recurse(lst,0,len(lst)-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment