Created
June 21, 2023 21:35
-
-
Save TruncatedDinoSour/4d4c767ac076797251da65312a11db01 to your computer and use it in GitHub Desktop.
very fast and good sorting algo
This file contains 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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
"""best sorting algorithm""" | |
from secrets import SystemRandom | |
from warnings import filterwarnings as filter_warnings | |
RAND: SystemRandom = SystemRandom() | |
def issorted(lst: list[int]) -> bool: | |
for idx in range(len(lst)): | |
for jdx in range(idx + 1, len(lst)): | |
if lst[jdx] < lst[idx]: | |
return False | |
return True | |
def sort(lst: list[int]) -> None: | |
while not issorted(lst): | |
RAND.shuffle(lst) | |
def main() -> int: | |
"""entry/main function""" | |
l: list[int] = list(range(5)) | |
RAND.shuffle(l) | |
print(l) | |
sort(l) | |
print(l) | |
return 0 | |
if __name__ == "__main__": | |
assert main.__annotations__.get("return") is int, "main() should return an integer" | |
filter_warnings("error", category=Warning) | |
raise SystemExit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment