A sidenote:
in order to get good results you should use a perceptually uniform representation of the colors
(R,G,B) isn't perceptually uniform this means that errors in the (R,G,B) space are not closely related
to the differences you perceve looking at the colors.
This is a problem, e.g., in the program by dvick to have 105 colors on msx1 (http://www.msx.org/BMPTO105.newspost3603.html) and could be solved by
passing to some p.u. color representation