1

I have 5 values which are -2, -1, 0, 1, 2. I want to calculate difference between two variables which contains the values from these given values.

Suppose I have two variables x and y. Suppose following cases :

x = 0, y = 0 i.e. (x == y) then return value should be 2.

x = 1, y = -1 or vice versa then the return value should be 0.

x = -2, y = 2 or vice versa then the return value should be -2.

I have to use this formula in a program.

1 Answers1

2

I have solved this by using following formula :

$$ d(x,y) = 2 - |x - y| $$

hardmath
  • 37,015
  • 1
    Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. – quid May 06 '15 at 14:56
  • @quid The description is in question itself. Please let me know if there is anything that is not understandable. – Sumit Madan May 06 '15 at 15:32
  • Sorry. This was an autogenerated comment. I did not get you meant this as a self-answer. Sorry, again. – quid May 06 '15 at 15:38