- Notifications
You must be signed in to change notification settings - Fork 363
Expand file tree
/
Copy pathBogoSortIn_python.py
More file actions
Latest commit
30 lines (25 loc) · 660 Bytes
/
Copy pathBogoSortIn_python.py
File metadata and controls
30 lines (25 loc) · 660 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
importrandom
defshuffle(arr):
foriinrange(len(arr)):
j=random.randrange(len(arr))
t=arr[i]
arr[i] =arr[j]
arr[j] =t
defis_sorted(arr):
foriinrange(1, len(arr)):
ifarr[i] <arr[i-1]:
returnFalse
returnTrue
defbogosort(arr):
randShuffles=0
whilenotis_sorted(arr):
shuffle(arr)
randShuffles+=1
print("Number of randShuffles:", randShuffles)
defmain():
arr= [random.randint(0, 100) for_inrange(10)]
print("The unsorted arr is:", arr)
bogosort(arr)
print("The sorted arr is:", arr)
if__name__=="__main__":
main()