8000 Add bogo sort implementation · CO18326/python@e6d9824 · GitHub
[go: up one dir, main page]

Skip to content

Commit e6d9824

Browse files
Will AdamsWill Adams
authored andcommitted
Add bogo sort implementation
1 parent 681901d commit e6d9824

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

sorting/bogo_sort.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Python implementation of Bogo sort
2+
3+
from random import shuffle
4+
5+
def bogo_sort(l):
6+
while not all(l[i] <= l[i+1] for i in xrange(len(l)-1)):
7+
shuffle(l)
8+
return l
9+
10+
# Tests
11+
if __name__ == '__main__':
12+
print bogo_sort([3, 2, 1])
13+
print bogo_sort([1000, 100, 10, 1])

0 commit comments

Comments
 (0)
0