File tree 2 files changed +23
-0
lines changed
chapters/sorting_searching/bogo
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ In code, it looks something like this:
23
23
[ import:4-27, lang:"c_cpp"] ( code/c/bogo_sort.c )
24
24
{% sample lang="js" %}
25
25
[ import:1-16, lang:"javascript"] ( code/js/bogo.js )
26
+ {% sample lang="py" %}
27
+ [ import:5-13, lang:"python"] ( code/python/bogo.py )
26
28
{% sample lang="hs" %}
27
29
[ import, lang:"haskell"] ( code/haskell/bogoSort.hs )
28
30
{% sample lang="cpp" %}
Original file line number Diff line number Diff line change
1
+ from __future__ import print_function
2
+ import random
3
+
4
+
5
+ def is_sorted (a ):
6
+ for i in range (len (a )- 1 ):
7
+ if a [i + 1 ] < a [i ]:
8
+ return False
9
+ return True
10
+
11
+ def bogo_sort (a ):
12
+ while not is_sorted (a ):
13
+ random .shuffle (a )
14
+
15
+ def main ():
16
+ a = [1. , 3 , 2 , 4 ]
17
+ bogo_sort (a )
18
+ print (a )
19
+
20
+ main ()
21
+
You can’t perform that action at this time.
0 commit comments