That was fun! I think by the last few levels, I had inadvertently arrived at a very simplified version of the quicksort algorithm :)