Solution to Alien Numbers practice problem from Google Code Jam