News for hackers. Stuff that matters.
Re:Is this the simplest (and most surprising) sorting algori... by InsideOutSanta on Monday February 24, 2025 @01:44PM (#43163221)
The problem is that you can look at this and, after a few seconds, think you've formed an intuition on how it must work, but your intuition is wrong. It seems like the only way to really show how weird this is would be by creating an animation that shows how it shuffles entries around.

(Edit) I gave it a shot: https://jsfiddle.net/odwh6cL5/45/

Re:Is this the simplest (and most surprising) sorting algori... by varunneal on Monday February 24, 2025 @03:43PM (#43164724)
very beautiful simple animation. Good visualization of the proof of the algo; namely, that at each step i of the outer loop the first i elements are sorted (this is easy to show via induction)
Re:Is this the simplest (and most surprising) sorting algori... by WantonQuantum on Monday February 24, 2025 @06:19PM (#43166125)
Thank you for this!
Re:Is this the simplest (and most surprising) sorting algori... by bunabhucan on Monday February 24, 2025 @06:40PM (#43166276)
Add bubble sort in parallel and race them against each other!
Re:Is this the simplest (and most surprising) sorting algori... by InsideOutSanta on Tuesday February 25, 2025 @04:01AM (#43169676)
Here you go: https://jsfiddle.net/790sfL21/30/

The difference between the two algorithms becomes even more apparent if you rerun the sort after the list is already sorted.

Re:Is this the simplest (and most surprising) sorting algori... by bunabhucan on Thursday February 27, 2025 @04:47PM (#43198868)
"Slower than bubblesort" is the acheivement here.
Re:Is this the simplest (and most surprising) sorting algori... by layer8 on Monday February 24, 2025 @07:06PM (#43166481)
Re:Is this the simplest (and most surprising) sorting algori... by Mithriil on Tuesday February 25, 2025 @10:46AM (#43173387)
The visualization helped me realize something: The index doesn't change after the swap, so you always end up with the biggest number "in hand" after a full deeper level iteration loop.
Re:Is this the simplest (and most surprising) sorting algori... by Mithriil on Tuesday February 25, 2025 @10:42AM (#43173345)
This looks like a cool progress bar.
Re:Is this the simplest (and most surprising) sorting algori... by InsideOutSanta on Tuesday February 25, 2025 @11:07AM (#43173664)
That's a neat idea!