0

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?

1 Answers1

1

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

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

User8976
  • 12,637
  • 9
  • 42
  • 107