Created
October 8, 2023 14:59
-
-
Save ZeroIntensity/c63e213f149da4863b2cb0b82c8fa9dc to your computer and use it in GitHub Desktop.
awful sorting algorithm
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 ctypes | |
import sys | |
assert sys.implementation.name == "cpython" | |
def mussolini(array: list[int]): | |
if not array: | |
return | |
highest = array[0] | |
for i in array: | |
if i > highest: | |
highest = i | |
if i < highest: | |
new = i | |
while new < highest: | |
new += 1 | |
size_i = sys.getsizeof(i) | |
size_new = sys.getsizeof(new) | |
i_bytes = (ctypes.c_ubyte * size_i).from_address(id(i)) | |
new_bytes = (ctypes.c_ubyte * size_new).from_address(id(new)) | |
ctypes.memmove(i_bytes, new_bytes, len(new_bytes)) | |
highest = new | |
if __name__ == "__main__": | |
my_array = [98, 90, 100, 103, 106, 50, 89, 140] | |
mussolini(my_array) | |
assert sorted(my_array) == my_array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment