I saw this tweet the other day:
Here's a vey strange Sorting Algorithm:
โ Fermat's Library (@fermatslibrary) December 4, 2017
For every element X on the sequence the program does this:
1) Sleeps for X seconds
2) Prints X
The clock starts simultaneously for all elements.
And it seemed like a good opportunity to demonstrate asyncio.
./sleepsort.py
contains a command line application that can sort positive integers by sleeping. It requires Python 3.7.
If you have poetry, you can run:
poetry run ./sleepsort.py 6 2 8 3 6 9
Run a test (that checks against sorted
) with
poetry run pytest