2011/05/20

4chan BBS - Genius sorting algorithm: Sleep sort
http://dis.4chan.org/read/prog/1295544154
常識を覆すソートアルゴリズム!その名も"sleep sort"! - Islands in the byte stream
http://d.hatena.ne.jp/gfx/20110519/1305810786
Sleep sort with AnyEvent - TokuLog 改メ tokuhirom’s blog
http://d.hatena.ne.jp/tokuhirom/20110519/1305814594
こういうのはGoが得意分野だよね。 package main

import (
    "os"
    "strconv"
    "syscall"
)

func main() {
    args := os.Args[1:]

    done := make(chan int64)
    for _, arg := range args {
        i, _ := strconv.Atoi64(arg)
        go func(i int64) {
            syscall.Sleep(i * 1e9)
            done <- i
        }(i)
    }
    for _ = range args {
        println(<-done)
    }
}
Posted at 01:08 | WriteBacks () | Edit
Edit this entry...

wikieditish message: Ready to edit this entry.






















A quick preview will be rendered here when you click "Preview" button.