Speed up the "from base" conversion algorithm

Inspired by a submission on http://exercism.io which I can't seem to find.