-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbogo.py
More file actions
28 lines (25 loc) · 775 Bytes
/
Copy pathbogo.py
File metadata and controls
28 lines (25 loc) · 775 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
import random
def bogosort(list):
for i in range(len(list)):
if i < len(list) - 1:
if list[i] <= list[i + 1]:
pass
else:
print("list not sorted, reshuffle:", list)
return False
else:
return True
a = list(random.randint(1, 1000) for i in range(8))
#creating loop, until find the sorted shuffle
while True:
#shuffle it
random.shuffle(a)
#creating control mechanism to check whether it's sorted or not
#if our function returned False (not sorted), it will keep shuffling it
if bogosort(a) == False:
continue
#if it's returned True, print the result and break the loop
else:
print("list sorted!")
print(a)
break