Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d103ea3

Browse filesBrowse files
authored
Merge pull request AllAlgorithms#54 from willdougadams/master
Add bogo sort implementation
2 parents 3c07851 + e6d9824 commit d103ea3
Copy full SHA for d103ea3

File tree

Expand file treeCollapse file tree

1 file changed

+13
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-0
lines changed

‎sorting/bogo_sort.py

Copy file name to clipboard
+13Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.