In color schemes, I would like to sort the hues, but would like to avoid 'big gaps', i.e. prefer 350,354,2,10,15
over 2,10,15,350,354
(when expressed as 0-360 degree values). What's the best approach of doing that (eg in php)? Is it finding the 'biggest gap' and start after that? Any better ideas?
If you don't have that many:
This algorithm is O(N^2) in the size of the of the list.
The main takeaway is that you only have N 'rotations' here. Decide a 'gappiness' statistic, and brute force it over all N rotations, and use the arrangement that minimizes the 'gappiness'.
Just find the biggest gap and put it in the beginning.