Skip to content

Instantly share code, notes, and snippets.

@ozkatz
Created May 26, 2013 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozkatz/5652202 to your computer and use it in GitHub Desktop.
Save ozkatz/5652202 to your computer and use it in GitHub Desktop.
A bogosort implementation in Python. For all your big data needs.
from random import shuffle
def is_ordered(l):
for i, x in enumerate(l):
if i == 0:
continue
if x < l[i - 1]:
return False
return True
def bogosort(l):
while True:
shuffle(l)
if is_ordered(l):
return l
if __name__ == '__main__':
print(bogosort([1, 7, 2, 84, 135, 23, 17, 180, 80, 323, 6]))
@ozkatz
Copy link
Author

ozkatz commented May 26, 2013

Also, loving l as a variable name. lol pep8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment