Skip to content

Instantly share code, notes, and snippets.

@robinhouston
Created September 26, 2011 21:56
Show Gist options
  • Save robinhouston/1243524 to your computer and use it in GitHub Desktop.
Save robinhouston/1243524 to your computer and use it in GitHub Desktop.
A Sleep sort implementation for http://visualsort.appspot.com/
pos = [0 ... VA.length]
rpos = [0 ... VA.length]
swap = (i, j) ->
VA.swap i, j
tmp = rpos[j]; rpos[j] = rpos[i]; rpos[i] = tmp
pos[rpos[i]] = i; pos[rpos[j]] = j
j = 0
for i in [0 ... VA.length]
v = VA.get(i)
do (v, i) ->
setTimeout ->
# Move the element that was originally in position i to position j
swap pos[i], j++
VA.play()
, 100 * v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment