Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,16 @@
|
|||
import random
|
||||
|
||||
def bogosort(l):
|
||||
while not in_order(l):
|
||||
random.shuffle(l)
|
||||
return l
|
||||
|
||||
def in_order(l):
|
||||
if not l:
|
||||
return True
|
||||
last = l[0]
|
||||
for x in l[1:]:
|
||||
if x < last:
|
||||
return False
|
||||
last = x
|
||||
return True
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
def in_order(l):
|
||||
return all( l[i] <= l[i+1] for i in xrange(0,len(l)-1))
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
import random
|
||||
def bogosort(lst):
|
||||
random.shuffle(lst) # must shuffle it first or it's a bug if lst was pre-sorted! :)
|
||||
while lst != sorted(lst):
|
||||
random.shuffle(lst)
|
||||
return lst
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import operator
|
||||
import random
|
||||
from itertools import dropwhile, imap, islice, izip, repeat, starmap
|
||||
|
||||
def shuffled(x):
|
||||
x = x[:]
|
||||
random.shuffle(x)
|
||||
return x
|
||||
|
||||
bogosort = lambda l: next(dropwhile(
|
||||
lambda l: not all(starmap(operator.le, izip(l, islice(l, 1, None)))),
|
||||
imap(shuffled, repeat(l))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue