Skip to content

Commit 2d04bd7

Browse files
VikingScientistButt4cak3
authored andcommitted
Added python Bogo Sort (#142)
1 parent 01c6fb8 commit 2d04bd7

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

CONTRIBUTORS.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ Maxime Dherbécourt
99
Jess 3Jane
1010
Pen Pal
1111
Chinmaya Mahesh
12-
Unlambder
12+
Kjetil Johannessen
13+
Unlambder

chapters/sorting_searching/bogo/bogo_sort.md

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ In code, it looks something like this:
2525
[import:2-17, lang:"java"](code/java/bogo.java)
2626
{% sample lang="js" %}
2727
[import:1-16, lang:"javascript"](code/js/bogo.js)
28+
{% sample lang="py" %}
29+
[import:4-12, lang:"python"](code/python/bogo.py)
2830
{% sample lang="hs" %}
2931
[import, lang:"haskell"](code/haskell/bogoSort.hs)
3032
{% sample lang="m" %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import random
2+
3+
4+
def is_sorted(a):
5+
for i in range(len(a)-1):
6+
if a[i+1] < a[i]:
7+
return False
8+
return True
9+
10+
def bogo_sort(a):
11+
while not is_sorted(a):
12+
random.shuffle(a)
13+
14+
def main():
15+
a = [1., 3, 2, 4]
16+
bogo_sort(a)
17+
print(a)
18+
19+
main()
20+

0 commit comments

Comments
 (0)