[chuck-users] sleep sort port

Kassen signal.automatique at gmail.com
Wed Jun 15 15:05:32 EDT 2011

Fellow ChucKists,

I just noticed this sorting algorithm;
http://dis.4chan.org/read/prog/1295544154 (should be work-safe, despite that

for those afraid of 4chan links and for reference, here is it;

function f() {
    sleep "$1"
    echo "$1"
while [ -n "$1" ]
    f "$1" &

example usage:
./sleepsort.bash 5 3 6 3 6 3 1 4 7

Since this is time-based and also spectacularly impractical it should be of
acute interest to present company.
I therefore ported this to ChucK which was so far lacking a sorting
algorithm that is consistent with our time-centric approach to programming.
int input[8];
for (int n; n< input.size(); n++) Std.rand2(0, 20) => input[n];

int output[false];

fun void arrayPrinter( int arg[] )
for (int n; n < arg.size(); n++) chout <= arg[n] <= " ";
chout <= IO.newline();

fun void waiter(int length)
length::second => now;
output << length;


for (int n; n< input.size(); n++) spork~waiter(input[n]);

while (output.size() < input.size()) second => now;


This will display a list of random numbers, spends some time on sorting
them, then displays the numbers again, but sorted.

Hope that's good for a smile for some.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20110615/646f39f6/attachment.html>

More information about the chuck-users mailing list