How to reverse a range of numbers

14.2k Views Asked by At

if I have a range of floating point numbers, specifically this: min: 0.5 max: 1.5 How do I reverse the order of a selected place in the range?

For instance if I pic 1.5 I would want my result to be 0.5. 1 would get 1 (I think), 0.5 would get 1.5, and any number in between would correspond to this reverse ordering.

2

There are 2 best solutions below

0
On BEST ANSWER

Note, that if you pick $x$ and $y$ is its reverse, then $x+y=2$ should hold. So, you can calculate the reverse by $$f(x)=2-x$$

0
On

Let the vector storing the numbers be $v$. Then $v(1)=0.5$ and $v(n)=1.25$ where $n\times 1$ is the size of your vector. Then form a new vector $u$ of size $n\times 1$ such that $$u(i)=v(n+1-i)$$ then $u$ contains the numbers in reversed order.