Skip to content

Instantly share code, notes, and snippets.

@maxfriedrich
Created December 10, 2014 20:51
Show Gist options
  • Save maxfriedrich/3652fc4925a7cc867ef2 to your computer and use it in GitHub Desktop.
Save maxfriedrich/3652fc4925a7cc867ef2 to your computer and use it in GitHub Desktop.
from random import shuffle
def mitte(a):
for i in range(1, len(a)):
if a[i] != a[i-1]:
return i
return 0
def zwergsort(n): # n >= 2
zwerge = ['s' if n % 2 == 0 else 'w' for n in range(n)]
shuffle(zwerge)
sortierte_zwerge = [zwerge[0], zwerge[1]]
for zwerg in zwerge[2:]:
sortierte_zwerge.insert(mitte(sortierte_zwerge), zwerg)
return sortierte_zwerge
for n in range(2, 100):
print zwergsort(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment