RGB Color Mixing
Here's an algorithm for mixing multiple RGB colors to create a single color.
- Separate the colors into Red, Green, and Blue components.
- Average all the Reds together, average all the Greens together, average all the Blues together.
- Put the average values back together into a resulting RGB.
Is this the right way to do it? I don't know! But it's the way we're going to implement in this problem. Your task is to take a collection of RGB strings of the form "#FF021A"
, mix them like the algorithm above, and return the resulting RGB string.
Note that each RGB string contains two hexadecimal digits for each component. You can round the averages to integers however you want.
Examples
(mix ["#FFFFFF" "#000000"]) ;=> "#7F7F7F" or "#808080" depending on how you round
(mix ["#FF0000" "#00FF00" "#0000FF"]) ;=> "#555555"
Thanks to this site for the challenge idea where it is considered Very Hard level in JavaScript.
Please submit your solutions as comments on this gist.
I'm trying to use this to expand my property testing skills. Does anyone have any thoughts on the properties that can be tested? The only one I've managed to come up with so far is idempotence.