Assigning numbers to triplets

45 Views Asked by At

I have a system of triplets $111,112,113,114,115,121,\cdots, 555$ mae out of the numbers $\{1,2,3,4,5\}$. So there will be total $5^3$ triplets. I want to assign to each triplet a unique number so that I can order the triplets according to that value. Moreover I should get back to the triplets from that number uniquely. Is there any way of assigning like this?

Thanks..

1

There are 1 best solutions below

1
On BEST ANSWER

We can explore base-$5$ positional notation :

for each triplet $abc$ consider base-5 "digits" $(a-1), (b-1), (c-1)$ and assign the number $$n = (a-1)\cdot 5^2 + (b-1)\cdot 5^1 + (c-1)\cdot 5^0\\ =(a-1)\cdot 25 + (b-1)\cdot 5 + (c-1)\cdot 1.\tag{1}$$

Reverse way: for given $n$ calculate its digits base-$5$ and increment each one by $1$: $$ c =(n \bmod 5)+1, \quad n_1 = \lfloor n/5 \rfloor; \\ b =(n_1 \bmod 5)+1, \quad n_2 = \lfloor n_1/5 \rfloor; \\ a =(n_2 \bmod 5)+1=n_2+1.\; \qquad\tag{2}$$


Example:

triplet $341$;
$n = (3-1)\cdot 25 + (4-1)\cdot 5+(1-1)\cdot 1=65$;

$c=(65 \bmod 5)+1 = \color{darkred}{1},\quad n_1=13$;
$b=(13 \bmod 5)+1 = \color{darkred}{4}, \quad n_2 = 2$;
$a=(2 \bmod 5)+1 =2+1= \color{darkred}{3};$
so, $\;abc=\color{darkred}{341}$.