Skip to main content
added 132 characters in body
Source Link
Roman
  • 2k
  • 9
  • 17

Wolfram Language (Mathematica), 6363 48 bytes

StringJoin@@{"#",IntegerString[Round[15{##}]&@@RGBColor@#,16]}&"#"<>Round[15List@@RGBColor@#]~IntegerString~16& 

Try it online!Try it online!

-15 bytes thanks to attinat! Replacing StringJoin with <> and compressing the syntax.

  1. RGBColor@# converts the input string to a color of the form RGBColor[r, g, b] with three floating-point arguments in the range 0..1.

  2. Round[15 {##}] &List @@ %%] multiplies thesethe list of three arguments by 15 and rounds them to the nearest integer. We now have a list of three integer values corresponding to the three desired hexadecimal digits.

  3. IntegerString[%, 16]%~IntegerString~16 converts this list of three integers to a list of three hexadecimal strings of one character each.

  4. StringJoin @@ {"#", %}"#"<>% prepends a # character and joins all these characters together.

Wolfram Language (Mathematica), 63 bytes

StringJoin@@{"#",IntegerString[Round[15{##}]&@@RGBColor@#,16]}& 

Try it online!

  1. RGBColor@# converts the input string to a color of the form RGBColor[r, g, b] with three floating-point arguments in the range 0..1.

  2. Round[15 {##}] & @@ % multiplies these three arguments by 15 and rounds them to the nearest integer. We now have a list of three integer values corresponding to the three desired hexadecimal digits.

  3. IntegerString[%, 16] converts this list of three integers to a list of three hexadecimal strings of one character each.

  4. StringJoin @@ {"#", %} prepends a # character and joins all these characters together.

Wolfram Language (Mathematica), 63 48 bytes

"#"<>Round[15List@@RGBColor@#]~IntegerString~16& 

Try it online!

-15 bytes thanks to attinat! Replacing StringJoin with <> and compressing the syntax.

  1. RGBColor@# converts the input string to a color of the form RGBColor[r, g, b] with three floating-point arguments in the range 0..1.

  2. Round[15 List @@ %] multiplies the list of three arguments by 15 and rounds them to the nearest integer. We now have a list of three integer values corresponding to the three desired hexadecimal digits.

  3. %~IntegerString~16 converts this list of three integers to a list of three hexadecimal strings of one character each.

  4. "#"<>% prepends a # character and joins all these characters together.

added 573 characters in body
Source Link
Roman
  • 2k
  • 9
  • 17

Wolfram Language (Mathematica), 63 bytes

StringJoin@@{"#",IntegerString[Round[15{##}]&@@RGBColor@#,16]}& 

Try it online!

  1. RGBColor@# converts the input string to a color of the form RGBColor[r, g, b] with three floating-point arguments in the range 0..1.

  2. Round[15 {##}] & @@ % multiplies these three arguments by 15 and rounds them to the nearest integer. We now have a list of three integer values corresponding to the three desired hexadecimal digits.

  3. IntegerString[%, 16] converts this list of three integers to a list of three hexadecimal strings of one character each.

  4. StringJoin @@ {"#", %} prepends a # character and joins all these characters together.

Wolfram Language (Mathematica), 63 bytes

StringJoin@@{"#",IntegerString[Round[15{##}]&@@RGBColor@#,16]}& 

Try it online!

Wolfram Language (Mathematica), 63 bytes

StringJoin@@{"#",IntegerString[Round[15{##}]&@@RGBColor@#,16]}& 

Try it online!

  1. RGBColor@# converts the input string to a color of the form RGBColor[r, g, b] with three floating-point arguments in the range 0..1.

  2. Round[15 {##}] & @@ % multiplies these three arguments by 15 and rounds them to the nearest integer. We now have a list of three integer values corresponding to the three desired hexadecimal digits.

  3. IntegerString[%, 16] converts this list of three integers to a list of three hexadecimal strings of one character each.

  4. StringJoin @@ {"#", %} prepends a # character and joins all these characters together.

Source Link
Roman
  • 2k
  • 9
  • 17

Wolfram Language (Mathematica), 63 bytes

StringJoin@@{"#",IntegerString[Round[15{##}]&@@RGBColor@#,16]}& 

Try it online!