Problem 60951. Extra colors
Context
In the RGB color system used by Matlab, the color is a 1 x 3 / row vector [R G B] with each value/component R, G, B in the range 0 <= component <= 1. Each color defined is associated to its name and a one letter abridged version of it. For instance [1 0 0] matches with 'red' and 'r' . [0 1 1] matches with 'cyan' and 'c' and is a balanced mix of one component of green [0 1 0] with one component of blue [0 0 1]. Refer to the LineSpec field in the documentation of plot function for further information and the list of registered colors.
Your mission (should you choose to accept it ;-)
Provide the corresponding code (output vector) to one of these three new / given colors (input full string or abridged) :
- 'violet' / 'v' is is an additive mix of one component of red with two components of blue;
- 'purple' / 'p' is a balanced additive mix of one component of magenta with one component of black;
- 'gray' / 'a' is a balanced additive mix of one component of white with one component of black.
Your algorithm must be case insensitive.
Forbidden functions
- regexp
- str2num
- assignin
Please don't forget to like if you appreciated solving this problem :-)
Solution Stats
Problem Comments
-
5 Comments
Show
2 older comments
William
on 3 Jul 2025
Test #4 is incomplete.
Dyuman Joshi
on 4 Jul 2025
@William, could you specify how it is incomplete?
Nicolas Douillet
on 6 Jul 2025
@William : you mean I could add more forbidden functions ?
Tim
on 7 Jul 2025
The problem statement uses 'a' for gray but the test suite uses 'g', which should mean green. Also, you could require the function to handle 'rgbcmywk' along with the new colors (and maybe include 'o' for orange and any others you can think of).
Nicolas Douillet
on 8 Jul 2025
Ok, thank you Tim :-) I will try to take this into account and improve. I already thought about orange, but it appears the real orange was not what I had in mind ( [1 0.5 0] ). The same goes for the pink.
Solution Comments
Show commentsProblem Recent Solvers12
Suggested Problems
-
12 Solvers
More from this Author42
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!