Translating Alien Numbers with Python   Nov 17, 2014

This brief post demonstrates a Python solution to the 2009 Google Code Jam challenge to translate between alien number systems.


The description from the problem page is as follows:

Problem Statement

The decimal numeral system is composed of ten digits, which we represent as "0123456789" (the digits in a system are written from lowest to highest). Imagine you have discovered an alien numeral system composed of some number of digits, which may or may not be the same as those used in decimal. For example, if the alien numeral system were represented as "oF8", then the numbers one through ten would be (F, 8, Fo, FF, F8, 8o, 8F, 88, Foo, FoF). We would like to be able to work with numbers in arbitrary alien systems. More generally, we want to be able to convert an arbitrary number that's written in one alien system into a second alien system.

Essentially the problem boils down to identifying the base each number system is in, dictated by the number of symbols/numerals they use and the sequence of the symbols. Then we must calculate the source number value and translate that into the base of the target number system using the target number system's symbols, simple really!


Tags for this post:

 Back