q / kdb +、55バイト
解決:
"#",raze{(last($)0x0 vs)each"h"$.0255*x[3]*x 0 1 2}100-
例:
q)"#",raze{(last($)0x0 vs)each"h"$.0255*x[3]*x 0 1 2}100-86 86 0 43
"#141491"
q)"#",raze{(last($)0x0 vs)each"h"$.0255*x[3]*x 0 1 2}100-28 14 0 6
"#adcef0"
q)"#",raze{(last($)0x0 vs)each"h"$.0255*x[3]*x 0 1 2}100-0 41 73 4
"#f59042"
説明:
かなり簡単ですが、0.0255
他のソリューションからトリックを盗みました(ありがとう!)。評価は右から左に行われます。
"#",raze {(last string 0x0 vs) each "h"$ .0255 * a[3] * a 0 1 2}100- / ungolfed
{ } / lambda function
100- / subtract from 100 (vector)
a 0 1 2 / index into a at 0, 1 and 2 (CMY)
a[3] / index into at at 3 (K)
* / multiply together
.0255 * / multiply by 0.255
"h"$ / cast to shorts
( ) each / perform stuff in brackets on each list item
0x0 vs / converts to hex, 1 -> 0x0001
string / cast to string, 0x0001 -> ["00", "01"]
last / take the last one, "01"
raze / join strings together
"#", / prepend the hash
ノート:
デフォルトで数値を丸めると、(_)
代わりにshortにキャストする前に3バイトがフロアにかかります。
CMYK
値を0
to から小数として取得できますか、それとも1
toにする必要がありますか?0
100