-1

A rather simple/complicated math problem I encountered whilst programming. Here's the simplified version of it:

a+c=e
b=absolute value of(X-R)
C=absolute value of(X-r)
R-r? 

a,c,e,b,X,R are all known but r isn't.

Edit

        if(x-R>0&&x-r>0) {//x-R is B and x-r is C
            int Rminusr=C-B;
        }else if(x-R>0&&x-r<0) {
            int Rminusr=-C-B;
        }else if(x-R<0&&x-r>0) {
            int Rminusr=B+C;
        }else if(x-R<0&&x-r<0) {
            int Rminusr=B-C;
        }else if(x-R==0) {
            int Rminusr=-r+x;
        }else if(x-r==0) {
            int Rminusr=R-x;
        }

this is what I got until i realized that i dont actually know r or X-r

halfer
  • 19,824
  • 17
  • 99
  • 186
Icarus
  • 501
  • 2
  • 16

1 Answers1

1

There's really only one equation here that matters, because it's the only one that involves r:

c = |X-r|

This means that one of the following is true:

c = X-r
c = -(X-r) = r-X

Which in turn implies that r has one of two possible values:

r = X-c
r = X+c

You need to introduce another constraint on r to know exactly which of those two values it is.

What are you doing these calculations for? There might be another way to accomplish your goal.

Welbog
  • 59,154
  • 9
  • 110
  • 123