From 0bcdd37f46c7a4709d21d62970a5f9e0bdb9bca3 Mon Sep 17 00:00:00 2001 From: Aviraj singh Date: Fri, 10 Oct 2025 17:52:13 +0530 Subject: [PATCH 1/3] Add Sleep Sort algorithm with definition and Python implementation --- sorts/sleep_sort.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 sorts/sleep_sort.py diff --git a/sorts/sleep_sort.py b/sorts/sleep_sort.py new file mode 100644 index 000000000000..661e90328f74 --- /dev/null +++ b/sorts/sleep_sort.py @@ -0,0 +1,38 @@ +import threading +import time + +def sleep_sort(arr): + """ + Sorts a list of positive integers using Sleep Sort. + + Args: + arr (list[int]): List of positive integers to sort. + + Returns: + list[int]: Sorted list in ascending order. + """ + result = [] + + def sleeper(x): + # Sleep for a duration proportional to the number + time.sleep(x * 0.01) # scale down to avoid long delays + result.append(x) + + threads = [threading.Thread(target=sleeper, args=(num,)) for num in arr] + + # Start all threads + for t in threads: + t.start() + + # Wait for all threads to finish + for t in threads: + t.join() + + return result + +# Example Usage +if __name__ == "__main__": + numbers = [4, 1, 3, 2] + sorted_numbers = sleep_sort(numbers) + print("Original:", numbers) + print("Sorted:", sorted_numbers) From 2c462b17b92d017032bb8ead099fe90b0f4b4f2c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 10 Oct 2025 12:31:31 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sorts/sleep_sort.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sorts/sleep_sort.py b/sorts/sleep_sort.py index 661e90328f74..cf38a3e017c0 100644 --- a/sorts/sleep_sort.py +++ b/sorts/sleep_sort.py @@ -1,13 +1,14 @@ import threading import time + def sleep_sort(arr): """ Sorts a list of positive integers using Sleep Sort. - + Args: arr (list[int]): List of positive integers to sort. - + Returns: list[int]: Sorted list in ascending order. """ @@ -19,17 +20,18 @@ def sleeper(x): result.append(x) threads = [threading.Thread(target=sleeper, args=(num,)) for num in arr] - + # Start all threads for t in threads: t.start() - + # Wait for all threads to finish for t in threads: t.join() return result + # Example Usage if __name__ == "__main__": numbers = [4, 1, 3, 2] From 2bfc4aa1cfe9ca59d5c80eeb265ec6a7817fa677 Mon Sep 17 00:00:00 2001 From: cclauss Date: Thu, 10 Sep 2026 21:03:10 +0000 Subject: [PATCH 3/3] updating DIRECTORY.md --- DIRECTORY.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 150e4e61ea06..38a7df0737e5 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -986,6 +986,7 @@ * [Doppler Frequency](physics/doppler_frequency.py) * [Escape Velocity](physics/escape_velocity.py) * [Grahams Law](physics/grahams_law.py) + * [Hamiltonian](physics/hamiltonian.py) * [Horizontal Projectile Motion](physics/horizontal_projectile_motion.py) * [Hubble Parameter](physics/hubble_parameter.py) * [Ideal Gas Law](physics/ideal_gas_law.py) @@ -1404,6 +1405,7 @@ * [Selection Sort](sorts/selection_sort.py) * [Shell Sort](sorts/shell_sort.py) * [Shrink Shell Sort](sorts/shrink_shell_sort.py) + * [Sleep Sort](sorts/sleep_sort.py) * [Slowsort](sorts/slowsort.py) * [Smoothsort](sorts/smoothsort.py) * [Stalin Sort](sorts/stalin_sort.py)