0
$\begingroup$

I'm attempting to write an algorithm that deals with colors for a video game, and I've come across a very simple problem that I can solve no problem, but have no idea how to write a foolproof function that works for any input.

What I need to do is find the opposite numerator given a fraction.

For example, I have $\frac {184}{255}$ The opposite would be $\frac {71}{255}$.

If I have $\frac {13}{100}$ the opposite would be $\frac {87}{100}$ $\frac {0}{100}$ is $\frac 11$ and $\frac {100}{100}$ is $\frac {0}{100}$.

How can I do this?

$\endgroup$
0
$\begingroup$

For finding opposite (as you defined) just subtract it from $1$.

As your examples say: $1- 184/255 = (255-184)/255 =71/255$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.