Created
November 29, 2020 04:44
-
-
Save arshinalbab/80120a3e20d34bcf04f419079b8714fe to your computer and use it in GitHub Desktop.
BogoSort Implemented in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from random import shuffle | |
| def is_sorted(data) -> bool: | |
| """Determine whether the data is sorted.""" | |
| return all(data[i] <= data[i + 1] for i in range(len(data) - 1)) | |
| def bogosort(data) -> list: | |
| """Shuffle data until sorted.""" | |
| while not is_sorted(data): | |
| shuffle(data) | |
| return data | |
| print(bogosort(["b", "a", "n"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment