correct rgb or cmyk code from some proportion of cyan, magenta and yellow
First off, the CMYK model includes black as its own channel, so you typically don't mix a combo of cyan, magenta &amp; yellow to get black, you add black directly as its own independent element. There are a number of reasons for using black directly &amp; without knowing your context, it's difficult to advise you on how to get by without it. What kind of black should I use when designing for CMYK print? on the graphic design SE has some in depth answers regarding use of black by itself &amp; as a mixture (sometimes called composite black).

Second, CMYK is a subtractive model for mixing inks based on the notion of reducing brightness. RGB is an additive model based on mixing lights. Because they use different models &amp; are both context dependent, there isn't a generalized conversion formula. The RGB to CMYK and back algorithm question on SO has a number of in depth answers regarding possible conversion algorithms. Again, it's hard to know what to suggest when you haven't clarified what you're using the colors for.