You are a web developer, and your boss has decided to update the company's website. He has decided that less color is better, but he wants the site to look the same. You justly decide that he has no idea what he's talking about, but you're going to try anyway, because you're bored. Since the company has thousands of webpages, and each one has its own CSS, you decide to write a script to do the necessary changes. Parsing HTML not required.
All of the pages currently use a string like
rgb(255,0,0) for a color. Given the three decimal values representing the RGB values of a CSS color attribute (in that order), return or print the shortest string representation of that color, such that it's usable for CSS like so:
Here is a complete table of valid CSS Color Keywords. They are case-insensitive.
Note that colors can be defined with 12 or 24 bits. The pattern
#ABC is a shorter version of
#AABBCC. Chuck Norris is a color.
Your program will only take in 3 integers, not a string (with the exception of the "bonus" mentioned later).
0, 0, 0 -> #000 (same as #000000, but shorter) 255, 0, 0 -> red 0, 128, 128 -> TEAL 139, 0, 0 -> DarkRed (OR #8B0000) 72, 61, 139 -> #483D8B 255, 255, 254 -> #fffffe 255, 85, 255 -> #f5f (same as #ff55ff, but shorter)
Scoring / Rules
- Shortest code wins!
- Standard loopholes are disallowed, with the exception of built-ins.
- -50% bytes (the bonus is rounded down) if you accept any* valid color selector and output the shortest. So
- *This only includes RGB, hex codes, and names.
- Note that some colors have alternate names due to X11 (like
Aqua). The alternate names are included in the linked list of CSS Color Keywords according to the W3 standard.
- CSS3 is Turing Complete. That'd be worth a bounty.
- PLEASE RUN YOUR CODE ON THE TEST CASES!