Sort with sleep
Posted: June 16th, 2011 | Author: chmullig | Filed under: Nerdery | Tags: programming, sleep, sort | No Comments »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 waitNo Comments »