Friday, July 10, 2015

to sleep, perchance to sort

A kind of fun Quora, What is the dumbest code ever made that has become famous? introduced me to sleep sort:

procedure printNumber(n)
sleep n seconds
print n

for arg in args
run printNumber(arg) in background
wait for all processes to finish

So if you have a list of n integers, it will launch n threads, and each individual thread will finish after whatever the number of seconds it is. When all the threads are done, you will have finished printing your sorted list!

This is obviously a terrible idea, but I kind of love how it moves the usual "work" of sorting to a side-effect byproduct. 

No comments:

Post a Comment