Sleep sort algorithm :-)

Someone just pointed me to the (joke) sleep sort algorithm, pointing out that it only works with non-negative numbers. But I realised that it even works with negative numbers in Sonic Pi! :slight_smile:

set_sched_ahead_time! 3

[3, 4, 1, -2, 2, 0, -1].each do |n|
  in_thread do
    sleep n
    print n
  end
end
=> Starting run 113

=> Schedule ahead time set to 3

{run: 113, time: -2.0}
 ├─ Timing warning: running slightly behind...
 └─ -2
 
{run: 113, time: -1.0}
 ├─ Timing warning: running slightly behind...
 └─ -1
 
{run: 113, time: 0.0}
 └─ 0
 
{run: 113, time: 1.0}
 └─ 1
 
{run: 113, time: 2.0}
 └─ 2
 
{run: 113, time: 3.0}
 └─ 3
 
{run: 113, time: 4.0}
 └─ 4
 
=> Completed run 113

=> All runs completed

=> Pausing SuperCollider Audio Servert
2 Likes