Answer the question
In order to leave comments, you need to log in
How can three numbers be encoded into one and then unambiguously deciphered?
Good day.
Please tell me how it is possible (and is it possible?) to turn the following:
Three two-digit numbers are given, one of them must be obtained two-digit.
The ranges of all three numbers are from 0 to 30.
That is, in theory, 30 + 30 + 30 = 90, that is, it should fit, but how to encode, so that you can unambiguously divide by three back?
OR
then in a five-digit?
OR
three numbers from 0 to 30 and three more numbers from 0 to 9, but also in five digits?
Answer the question
In order to leave comments, you need to log in
As usual
code = number1+Base*(number2+Base*number3)
Base in your case 30-1+1=30
decoding
Number3 = code mod Base^2
Number2 = (code - Number3 * Base^2) mod Base
Number1 = code - Number3 * Base^2 - Number2 * Base
Let's try to fit in a 4-digit number:
10 -->> 36
30+31+31 = 6HWB
31+31+30 = 6PM2
31+30+31 = 6PJB
In this case, everything is already encoded so that it can be unambiguously divided back.
If we assume that from 0 to 30 in the 4-ary number system, then we already fit in 3 characters.
4 -->> 36
30+31+31 = 2JH
31+31+30 = 2QK
31+30+31 = 2Q5
Come up with your own number system to fit in 2 characters.
PS It seems that I did not make a mistake anywhere :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question