Skip to content

Instantly share code, notes, and snippets.

@clementi
Created July 6, 2018 19:25
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 clementi/935beba8ffac21362f034e7e0acca5f2 to your computer and use it in GitHub Desktop.
Save clementi/935beba8ffac21362f034e7e0acca5f2 to your computer and use it in GitHub Desktop.
Bogosort in Python
import random
def is_sorted(data):
for i in range(len(data) - 1):
if data[i] > data[i+1]:
return False
return True
def bogosort(data):
_data = data
while not is_sorted(_data):
_data = random.sample(_data, k=len(_data))
return _data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment