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
Diff to Previous Revision
--- revision 2 2011-11-02 22:56:24
+++ revision 3 2011-11-21 19:58:14
@@ -1,6 +1,7 @@
-from math import *
+mod = lambda n,m: n%m
def baseExpansion(n,c,b):
- j = 0
- base10 = sum([pow(c,len(n)-k-1)*int(n[k]) for k in range(0,len(n))])
- while floor(base10/pow(b,j)) != 0: j = j+1
- return "".join(list(map(str,[floor(base10/pow(b,j-p)) % b for p in range(1,j+1)])))
+ 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