Skip to content

Instantly share code, notes, and snippets.

@akionsight
Created August 19, 2021 11:26
Show Gist options
  • Save akionsight/50d4ef823f80ba497b7936f718e1cb4b to your computer and use it in GitHub Desktop.
Save akionsight/50d4ef823f80ba497b7936f718e1cb4b to your computer and use it in GitHub Desktop.
Bogosort - the worst sort
import random
from typing import List
import time
def sort_list(list, list_length):
shuffled_list = random.sample(list, list_length)
return shuffled_list
pass
def check(old_list, new_list):
if old_list.sort() == new_list:
return True
return False
pass
def main(list_of_num: List[int]):
start_time = time.time()
while True:
shuffled_list = sort_list(list_of_num, len(list_of_num))
IsSorted = check(list_of_num, shuffled_list)
if IsSorted:
print(shuffled_list)
print('done')
end_time = time.time()
print(f"Time taken: {end_time - start_time}")
break
else:
continue
main([3, 6, 4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment