Google Code Jam – Alien Numbers
The problem:
This problem is basically asking us to do conversions from base-X to base-Y. To do that, we’re going to do 2 conversions: one from base-X to base-10, then one from base-10 to base Y.
The conversion for base-10 is pretty simple. If we have a number in base-3 such as 201, then that can be represented in base-10 by the following: (2 * 3^2) + (0 * 3^1) + (1 * 3^0) = 19.
To convert to base-Y, we’re going to use the following method (using base-5 for our conversion and 19 (base-10) as our example).
19 / 5 = 3 R 4
3 / 5 = 0 R 3
We then take those remainders and write them down in reverse, so 19 (base-10) = 34 (base 5). Converting the numbers to the “Alien” numbers is a simple process of matching up the digits with their corresponding index in the given alien numbers.