I believe I may have it working: each time through the outer for-loop it adds all the elements of the array in between the current position and the first one.