今天看到一個帖子
Man
朋友
#!/bin/bash
function f() {
sleep
echo
}
while [
do
f
shift
done
wait
example usage:
再帖幾個其他常用版本
JAVA版
[java]
public class SleepSort {
public static void main(String[] args) {
int[] ints = {
SortThread[] sortThreads = new SortThread[ints
for (int i =
sortThreads[i] = new SortThread(ints[i])
}
for (int i =
sortThreads[i]
}
}
}
class SortThread extends Thread{
int ms =
public SortThread(int ms){
this
}
public void run(){
try {
sleep(ms*
} catch (InterruptedException e) {
// TODO Auto
e
}
System
}
}
PHP版
[php]
<?php
$pids = array()
for ($i=
{
if (($pid = pcntl_fork()) ==
{
$sleep = intval($argv[$i])
sleep($sleep)
echo $sleep
exit()
}
else if ($pid ==
{
die()
}
else
{
$pids[] = $pid;
}
}
foreach($pids as $pid)
pcntl_waitpid($pid
?>
php sleepsort
JS版
[javascript]
// Javascript
function lazySort(list
var result = [];
list
setTimeout(function() {
result
if(result
callback(result)
}
}
})
}
lazySort([
Ruby版
[ruby]
ARGV
還有很多冷門語言版本
該貼有
路人A:
Oh god
But I don
哦
路人B:
If the difference between any two of the numbers is too small
如果兩個數之間的差距太小
路人C:
What about
If you slept exp(n) instead of n it could easily include negative integers too!
排
路人D:
Someone email this to Knuth
你可以給Knuth發郵件了
路人E:
I think thats brilliant :)
Would be fun to design a hardware sorter
這招挺高
路人F:
This has a best case O(n) and an infinity high worst case
它有一個最好的O(n)的時間復雜度和一個無窮大的最壞復雜度
路人G:
I heartily disagree with all the attempts to downplay the brilliance of the sleep sort algorithm
Given that you need nearly no computing in each of the threads
Oh
Sure
我由衷的不同意那些低估sleepsort這個天才算法的舉動
在每個線程中給出你幾乎不需要計算的部分
還有我提到的這個方法能在雲端運行不?
總之
路人H:
pretty fucking cool
太TMD的cool了!
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25620.html