This algorithm converts a base c number into a base b number. Parameters c and b are arbitrary are not constrained by any bounds. The input n is a list and the output is a list.
1 2 3 4 5 6 7
mod = lambda n,m: n%m def baseExpansion(n,c,b): i = len(n) base10 = sum([pow(c,i-k-1)*n[k] for k in range(i)]) j = int(ceil(log(base10 + 1,b))) baseExpanded = [mod(base10//pow(b,j-p),b) for p in range(1,j+1)] return baseExpanded
>>> baseExpansion([1,2,3],5,3) [1,1,0,2]