Created
February 24, 2024 11:16
-
-
Save Kur0den/dac48780f274407fd535442d99a40be6 to your computer and use it in GitHub Desktop.
bogo sort
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
| import random | |
| import time | |
| def main(): | |
| length = int(input("length: ")) | |
| sort_list = [i for i in range(1, length + 1)] | |
| c = 0 | |
| start_time = time.time() | |
| while True: | |
| c += 1 | |
| flag = True | |
| random.shuffle(sort_list) | |
| print(sort_list, f"count: {c}") | |
| for i, j in enumerate(sort_list): | |
| if i == 0: | |
| continue | |
| if j != sort_list[i - 1] + 1: | |
| flag = False | |
| break | |
| if flag: | |
| break | |
| end_time = time.time() | |
| print(f"実行時間: {round(end_time - start_time, 3)}s") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment