1
$\begingroup$

I'm trying to find a function that can convert each number (I mean natural numbers) in the range M..N to another number in the same range. Later I need to convert it back.

Let's take the 0..99 range for example. A very easy solution is:

b = 99 - a later to find a from b: a = 99 - b. And we can be sure that a and b will be in the 0..99 range.

What I want is the following If I convert all numbers from the linear series 0,1,2,3,4..99 with the function above I get 99, 98, 97, 96, 95..0, which is another linear one.

I would like to convert 0..99 to a non-linear series, but remaining in the same range.

Something like: 0 -> 11; 1 -> 52; 2 -> 77; etc. and later convert these numbers back.

Is there a mathematical function that can do this?

EDIT The function can be also an algorithm containing conditions, loops, etc. I will implement this in a programming language.

  • 0
    Can you be more specific please?2012-12-16

2 Answers 2

1

A good function for this is the modulo operator.

$f(n)=an\bmod{100}$

The choice of $a$ is up to you, but if $\gcd(a,100)=1$, then the mapping will be bijective, and the inverse function is

$f^{-1}(n)=bn\bmod{100},$

where $b$ is the unique integer such that $ab\equiv1\pmod{100}$. (This number can be found using the Euclidean algorithm.)

  • 0
    I really like this idea. Thank you!2012-12-16
1

Write thenumbers $0,\ldots,99$ on cards, shuffle them and write down there new order. E.g. if the first three cards read $11, 52, 77$ let your first function map $0\mapsto 11$, $1\mapsto 52$, $2\mapsto 77$ and so on. At the same time note the inverse function by writing a second table where in each row you note at which place in the seqeunce a number occured. Thus after the first three cards you will have noted $11\mapsto 0$, $52\mapsto 1$, $77\mapsto 2$.

These two arrays define functiuons that are inverse of each other as required.

  • 0
    Thank you for your answer Hagen! This is a possible solution I can implement.2012-12-16