Last active
July 1, 2018 23:19
-
-
Save tashian/acfe24c007d1c1f1aacfa571481af76e to your computer and use it in GitHub Desktop.
Bad algorithms #1: bad sort!
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 badsort(l): | |
done = False | |
loops = 0 | |
while not done: | |
loops += 1 | |
random.shuffle(l) | |
done = True | |
for i in range(len(l)-1): | |
if l[i] > l[i+1]: | |
done = False | |
break | |
return l, loops | |
print(badsort([1,2,5,8,122,2,3,11,4,6])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment