Fellow ChucKists, I just noticed this sorting algorithm; http://dis.4chan.org/read/prog/1295544154 (should be work-safe, despite that URL) for those afraid of 4chan links and for reference, here is it; #!/bin/bash function f() { sleep "$1" echo "$1" } while [ -n "$1" ] do f "$1" & shift done wait 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. ----------------------8<------------------------------------- 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; } arrayPrinter(input); for (int n; n< input.size(); n++) spork~waiter(input[n]); while (output.size() < input.size()) second => now; arrayPrinter(output); ---------------------------------------------8<---------------------------------- 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. Yours, Kas.
2011/6/15 Kassen
Fellow ChucKists, I just noticed this sorting algorithm; http://dis.4chan.org/read/prog/1295544154 (should be work-safe, despite that URL) for those afraid of 4chan links and for reference, here is it;
That's pretty amazing! A quick hack to make it output sound ( I made it twice as fast to actually keep you guys entertained): SqrOsc s => ADSR a => dac; 0 => s.freq; a.set(.5,0,0,0); 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/2.0)::second => now; 880 - 44*length => s.freq; a.keyOn(); //<<<length>>>; output << length; } arrayPrinter(input); for (int n; n< input.size(); n++) spork~waiter(input[n]); while (output.size() < input.size()) second => now; arrayPrinter(output); Cheers
*chuckles*
On Thu, Jun 16, 2011 at 1:44 AM, Lucas Zawacki
2011/6/15 Kassen
: Fellow ChucKists, I just noticed this sorting algorithm; http://dis.4chan.org/read/prog/1295544154 (should be work-safe, despite that URL) for those afraid of 4chan links and for reference, here is it;
That's pretty amazing!
A quick hack to make it output sound ( I made it twice as fast to actually keep you guys entertained):
SqrOsc s => ADSR a => dac; 0 => s.freq; a.set(.5,0,0,0);
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/2.0)::second => now; 880 - 44*length => s.freq; a.keyOn(); //<<<length>>>; output << length; }
arrayPrinter(input);
for (int n; n< input.size(); n++) spork~waiter(input[n]);
while (output.size() < input.size()) second => now;
arrayPrinter(output);
Cheers _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- Release me, insect, or I will destroy the Cosmos!
participants (3)
-
Kassen
-
Lucas Zawacki
-
Stefan Blixt