Created
May 26, 2013 09:30
-
-
Save ozkatz/5652202 to your computer and use it in GitHub Desktop.
A bogosort implementation in Python. For all your big data needs.
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
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])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also, loving
l
as a variable name. lol pep8