chmullig.com » sort http://chmullig.com Chris Mulligan's blog on life, computers, burritos, school Tue, 21 Apr 2015 15:41:14 +0000 en-US hourly 1 http://wordpress.org/?v=4.2.2 Sort with sleep http://chmullig.com/2011/06/sort-with-sleep/ http://chmullig.com/2011/06/sort-with-sleep/#comments Fri, 17 Jun 2011 02:24:43 +0000 http://chmullig.com/?p=366 Inspired by an Ars thread that was inspired by a 4chan thread found on reddit, it’s an interesting sort idea for integers.

Basically, sort a list of integers by spawning a new thread or process for each element then sleep for the value of that element then print out that element. Here’s the original bash example, but I’d love to see other crazy languages.

#!/bin/bash
function f() {
    sleep "$1"
    echo "$1"
}
while [ -n "$1" ]
do
    f "$1" &
    shift
done
wait
]]>
http://chmullig.com/2011/06/sort-with-sleep/feed/ 0