The algorithm you explain is basically: "A color consists of two RGB components. Let the strongest RGB component be S and the other component O. Create 255 variations where you let S be (255) and O ranges from 0 to 255."
E.g. all of the below example yield the same result:
a) rgb(0,100,200)
b) rgb(0,199,200)
c) rgb(0,254,255)
d) rgb(0,1,2)
Result: rgb(0,[0-255],255)
This means you only have a 6 variations.
- Red is the largest component, Green next largest => rgb(255,[0-255],0)
- Red is the largest component, Blue next largest => rgb(255,0,[0-255])
- Green is the largest component, Red next largest => rgb([0-255],255,0)
- Green is the largest component, Blue next largest => rgb([0-255],0,255)
- Blue is the largest component, Red next largest => rgb([0-255],0,255)
- Blue is the largest component, Green next largest => rgb(0,[0-255],255)
The intention of your algorithm is not clear, so I am guessing your use case is actually different from what you explain. It does not handle colors with either 1 or 3 components (most colors actually).
If your goal is to find similar colors (e.g. a color in a certain distance) there are better approaches. For example you could convert your colors to a HSV color space (Hue, Saturation, Value) and then say that the color is similar if the either of the components H, S or V are +/- 10 steps from your original.
E.g.:
rgb(255,100,0) => hsv(24,100,100)
Your range is then hsv([14-34],[90-110],[90-110])