Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Genius sorting algorithm: Sleep sort

Name: Anonymous 2011-01-20 12:22

Man, am I a genius. Check out this sorting algorithm I just invented.


#!/bin/bash
function f() {
    sleep "$1"
    echo "$1"
}
while [ -n "$1" ]
do
    f "$1" &
    shift
done
wait


example usage:
./sleepsort.bash 5 3 6 3 6 3 1 4 7

Name: Anonymous 2011-06-16 1:10

>>185
182 here. It was a thinking error, based on the absurd assumption that the scheduler doesn't sort. And yes, I can BBCode till your heart stops.

My remaining point is that, whatever algorithm the scheduler uses, all sleepsort does is pop items off it in slow motion (or not-so-slow motion if you can get a precise enough timing signal.) There's no good reason to not simply implement the scheduler's algorithm directly, instead.

Newer Posts