I'm looking for a formula in order to map Integers from a Range A to another Range B.
A={0,1,2,3,4,5}
B={1,2,3}
The mapping that I'm trying to achieve is:
0 --> 1
1 --> 1
2 --> 2
3 --> 2
4 --> 3
5 --> 3
How can I do it, such that it would adapt also to different ranges? E.g:
C={0,1,2}
0 --> 1
1 --> 2
2 --> 3
D={1,2,3,4,5,6,7,8,9,10}
1 ---> 1
2 ---> 1
3 ---> 1
4 ---> 2
5 ---> 2
6 ---> 2
7 ---> 2
8 ---> 3
9 ---> 3
10 --> 3
Right now I'm using this conversion from here but it doesn't behave as I would have expected.
Since your sets are finite, you can specify the function just by specifying the mapping of each element. So, you have already fully defined your function. However, if you want a simple formula then you could use this:
$$x \rightarrow \lfloor \frac{x}{2}\rfloor + 1$$
If your steps consist only of consecutive integers then you should be able to adjust this formula easily.
Your second example is even simpler:
$$x \rightarrow x + 1$$
Further detail.
For the more general case of the ranges $\{a, ..., b\}$ to $\{c, ..., d\}$, first consider the simpler problem of mapping the real number ranges $[a, b]$ to $[c, d]$. This function would do it:
$$x \rightarrow \frac{(d - c)}{(b - a)}(x - a) + c$$
Now, for the integer case, just add the floor function.
$$x \rightarrow \lfloor \frac{(d - c)}{(b - a)}(x - a) + c \rfloor$$
The real version of the function will be a bijection (one to one and onto) but the integer version will only be if the two sets have the same size. Otherwise, it might fail to be injective (one to one) or surjective (onto).