# Variable weight according to distance.

So I have a range of numbers for this example I would say something like 0 to 25. Within this range if I get a number lets say 11, then for each number that between my goal I it weighs more depending on the range.

So in this case of the range being 0 to 25, and I have the number 11 and I am trying to point it out, but instead I point out 13 this would mean the weight of the number = 2.

Now what I would like to achieve is to have a modifier that modifies the weight according to number.

So as example that if you have 0 to 50, and you number was 11, and you chose 16 that the weight would also be 2.

I am usually pretty okay with basic mathematics, but I don't know what category this is in since I have no clue on where to start.

UPDATE: the chose number can also be lower then the given number. Each distance will still add weight, depending on range.

• It seems you want to play around with the absolute value $|11-x|$, where $x$ is the chosen number. There is, however, not an easy way to reproduce the samples you gave. – Lord_Farin Nov 26 '13 at 8:50
• Perhaps not easy but is it possible using basic arithmetic ? Because I need it to be able to change the range and the chosen number, and the distance between the given number and the chosen x may vary, as the given and the chosen number will. But in each range there should a constant increase in weight depending on the range. – Maarten Nov 26 '13 at 8:57
• If by "constant increase" you mean linear (the weight of $15$ wrt. $11$ is twice as high as that of $13$ wrt. $11$) then that is enough information to be able to answer your question. Someone will write an answer when it'll get reopened. – Lord_Farin Nov 26 '13 at 8:59
• Thank you thus far, I hope someone can solve it for me. – Maarten Nov 26 '13 at 9:02

The relevant quantity to manipulate is $|x_0-x|$, the distance between the target $x_0$ and the selected number $x$.

The simplest possible solution is:

$$w = \lambda |x_0 - x|$$

with $\lambda$ a constant whose value may be chosen appropriately, for example in terms of the length of the interval $[a,b]$ to choose from, that is, $b-a$.

If you want the weight to increase faster farther from $x_0$, you can use higher powers of $|x_0-x|$, e.g. $|x_0-x|^2$. A combination is also possible:

$$w = \lambda |x_0-x| + \mu |x_0-x|^2$$

The possibilities are endless.

• Thanks now I cant at least tell my teacher, am not crazy. And that the it isn't solvable by means of basic arithmetic. – Maarten Nov 29 '13 at 11:53