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 e6d9824

Browse filesBrowse files
Will AdamsWill Adams
Will Adams
authored and
Will Adams
committed
Add bogo sort implementation
1 parent 681901d commit e6d9824
Copy full SHA for e6d9824

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.