I recently perused Donald Knuth's website and saw that he once had a lecture called "Constructing bubblesort at random: one-dimensional particle physics". As a physicist and software engineer, I naturally found this interesting. So this short bit of code takes a chain of 1s and 0s, as specified below, and sorts them at random. It also tells you how many passes it takes. Also, I'm not yet clear on how this relates to physics, at least not in a detailed sense. I'll have to think about that some more.
Here's a note from one of the papers Knuth linked to:
Start with infinitely many 1s followed by infinitely many 0s; then randomly interchange adjacent elements that are out of order.
The physics connection becomes a bit more clear if you imagine a 1D lattice, where the 1s are particles and the 0s are vacancies. Now, pick any site k and ask how many particles are to the right of site k. Call the result
It might be interesting to track how