Created
July 6, 2018 19:25
-
-
Save clementi/935beba8ffac21362f034e7e0acca5f2 to your computer and use it in GitHub Desktop.
Bogosort in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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