# Enumerate mixed-base numbers without a hash table

I'm using a mixed-base number to represent some data. E.g. $4_6 3_6 2_6 0_3 1_3 2_3$. As you can see the bases for the first and last 3 numbers are 6 and 3 respectively.

In the past, this number had the same base (6), so it was just a matter of converting from base 6 to base 10 and I was guaranteed a unique number in base 10 for a corresponding number in base 6.

I'd like to avoid setting up a hash table where the string 432012 maps to (say) 1342.

Now, I'm trying to figure out how to do the same for this mixed-base number ; any suggestions?

Would this work?

$$4_6 3_6 2_6 0_3 1_3 2_3 = 4 \cdot 6^5 + 3 \cdot 6^4 + 2 \cdot 6^3 + 0 \cdot 3^2 + 1 \cdot 3^1 + 2 \cdot 3^0$$

-

With your approach, numbers from $27=1+2_32_32_3$ to $215=1_60_30_30_3-1$ are not representable. I would do $4_63_62_60_31_32_3\ \$ as $4\cdot 6^2\cdot 3^3 + 3\cdot 6^1 \cdot 3^3 +2\cdot 6^0 \cdot 3^3 + 0\cdot 3^2+1\cdot 3^1 +2\cdot 3^0=4433.\ \$ You have to carry from each position with its particular base. Then all numbers will be representable.
Great! $555222$ corresponds to 5831 which is correct since there are a total of 5832 permutations. –  Jacob Aug 8 '11 at 19:14
The method is essentially the same as for a fixed base. The expression $$4_63_62_60_31_32_3$$ represents $$4\cdot 6^5 + 3\cdot 6^4 +2\cdot 6^3 + 0\cdot 3^2+1\cdot 3^1 +2\cdot 3^0.$$
Conversion to base $10$ is now just a calculation. I get $35429$ (the answer is given so that you can check). If there are significant length chunks to the same base, there are tricks to speed up the computation. But in the sort of application you mention, the powers that might be needed should be stored as constants.