Wednesday, October 26, 2011

Sleep Sort

A kind of neat sorting algorithm if, for some reason, you had a machine that had unlimited interrupts, and unlimited running time, but had almost no CPU power to do other sorts, perhaps biological computing?


 1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash
function f() {
sleep "$1"
echo "$1"
}
while [ -n "$1" ]
do
f "$1" &
shift
done
wait

No comments:

Post a Comment