examples stoogesort18 1 0 7 1 1 2 2 7 1 1 0 2 2 18 1 stoogesort if first element is smaller than the last then swap them if there are more than 2 elements in the array recursively sort first 23 elements recursively sort last 23 elements recursively sort first 23 elements examples stooge_sort 18 1 0 7 1 1 2 2 7 1 1 0 2 2 18 1 stooge_sort if first element is smaller than the last then swap them if there are more than 2 elements in the array recursively sort first 2 3 elements recursively sort last 2 3 elements recursively sort first 2 3 elements
def stooge_sort(arr: list[int]) -> list[int]:
    
    stooge(arr, 0, len(arr) - 1)
    return arr


def stooge(arr: list[int], i: int, h: int) -> None:
    if i >= h:
        return

    
    if arr[i] > arr[h]:
        arr[i], arr[h] = arr[h], arr[i]

    
    if h - i + 1 > 2:
        t = (int)((h - i + 1) / 3)

        
        stooge(arr, i, (h - t))

        
        stooge(arr, i + t, (h))

        
        stooge(arr, i, (h - t))


if __name__ == "__main__":
    user_input = input("Enter numbers separated by a comma:\n").strip()
    unsorted = [int(item) for item in user_input.split(",")]
    print(stooge_sort(unsorted))