Simple Formula to workout intervals

30 Views Asked by At

Say we have scale from $1$ to $12$ We pick two numbers on this scale and trying to figure the shortest distance. Say $x_1 = 2, x_2 = 4$ and we need to figure out y which in this case would be $y = 2$

Here is some examples:

$x_1 = 2, x_2 = 11$, $Y$ would be equal $2$

$x_1 = 1, x_2 = 5$, $Y$ would be equal $4$

$x_1 = 2, x_2 = 10$, $Y$ would be equal $3$

What would be the formula/equation for this? It's like clock with $12$ hours and we need to find shortest distance between $2$ numbers

Any help would be much appreciated.

1

There are 1 best solutions below

2
On BEST ANSWER

Firstly, for $x_1 = 2$, $x_2 = 11$, I believe $Y$ should be 3.

What you are describing as cycling around a clock is called modular arithmetic. So using the values above, $(x_1 - x_2) \mod 12 = (2 - 11) \mod 12 = -9 \mod 12 = 3$.

I believe you can go from here to find a formula for Y.