Skip to content

Instantly share code, notes, and snippets.

@tashian
Last active July 1, 2018 23:19
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 tashian/acfe24c007d1c1f1aacfa571481af76e to your computer and use it in GitHub Desktop.
Save tashian/acfe24c007d1c1f1aacfa571481af76e to your computer and use it in GitHub Desktop.
Bad algorithms #1: bad sort!
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