Needs a shuffle() function - can't bogosort without it.
Show HN: Write a sort, watch it go
11–20 of 89 posts
Re: Show HN: Write a sort, watch it go
#12I wanted to implement the sleep sort algorithm, but I can't use
VA = [4, 2, 5, 7];
for(x=0; x
it tells me I can't use "var". And when I remove that I get some syntax error.
Any nice alternative way to implement a sleep sort in coffescript?Re: Show HN: Write a sort, watch it go
#13[deleted]
Re: Show HN: Write a sort, watch it go
#14[deleted]
Re: Show HN: Write a sort, watch it go
#15>Nothing will display if there is an infinite loop.
Did someone solve the halting problem while I wasn't looking?
Re: Show HN: Write a sort, watch it go
#16Hash sort is surprisingly fast:
for x in [0 ... VA.length]
ind = VA.get(x)-1
VA.swap(x, ind + VA.length)
for x in [0 ... VA.length]
VA.swap(x, x + VA.length)Re: Show HN: Write a sort, watch it go
#17[deleted]
Re: Show HN: Write a sort, watch it go
#18The quicksort implementation is incorrect. The code simply picking the left-most element as the pivot, and as a result it becomes pathologically slow for nearly-sorted array -- for example, run bubblesort then quicksort, or run quicksort twice -- not to mention potential stack overflow problem due to O(N) recursive call.
Re: Show HN: Write a sort, watch it go
#19Radix-exchange sort:
sort = (begin, end, bit) ->
i = begin
j = end
mask = 1 begin
sort(begin, i, bit - 1)
if bit and i Re: Show HN: Write a sort, watch it go
#20It's fantastic. I don't know CoffeeScript so all I did was compare the pre-written ones to each other and see if they did what I expected them to do, but it's a nice visual representation. The only problem I have with it is that the neon yellow on black with a gray/white background can be pain inducing, especially when moving quickly.
Speaking of pain inducing, I found watching the bubble sort very pain inducing! I've always known it was slow compared to other options, but this make you never want to see the thing mentioned again!