Skip to content

Create quantum_bogo_sort.py #12028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions sorts/quantum_bogo_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
def quantum_bogo_sort(arr: list[int]) -> list[int]:
"""
Quantum Bogo Sort is a theoretical sorting algorithm that uses quantum mechanics to sort the elements.

Check failure on line 3 in sorts/quantum_bogo_sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

sorts/quantum_bogo_sort.py:3:89: E501 Line too long (106 > 88)

Check failure on line 3 in sorts/quantum_bogo_sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

sorts/quantum_bogo_sort.py:3:89: E501 Line too long (106 > 88)
It is not practically feasible and is included here for humor.

Reference:
https://en.wikipedia.org/wiki/Bogosort#:~:text=achieve%20massive%20complexity.-,Quantum%20bogosort,-A%20hypothetical%20sorting

:param arr: list[int] - The list of numbers to sort.
:return: list[int] - The sorted list, humorously assumed to be instantly sorted using quantum superposition.

Check failure on line 10 in sorts/quantum_bogo_sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

sorts/quantum_bogo_sort.py:10:89: E501 Line too long (112 > 88)

Check failure on line 10 in sorts/quantum_bogo_sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

sorts/quantum_bogo_sort.py:10:89: E501 Line too long (112 > 88)

Example:
>>> quantum_bogo_sort([2, 1, 4, 3])
[1, 2, 3, 4]

>>> quantum_bogo_sort([10, -1, 0])
[-1, 0, 10]

>>> quantum_bogo_sort([5])
[5]

>>> quantum_bogo_sort([])
[]
"""
return sorted(arr) # Sorting is assumed to be done instantly via quantum superposition

Check failure on line 25 in sorts/quantum_bogo_sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

sorts/quantum_bogo_sort.py:25:89: E501 Line too long (91 > 88)

Check failure on line 25 in sorts/quantum_bogo_sort.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

sorts/quantum_bogo_sort.py:25:89: E501 Line too long (91 > 88)


if __name__ == "__main__":
my_array: list[int] = [2, 1, 4, 3]
print(quantum_bogo_sort(my_array))
Loading