Welcome, guest | Sign In | My Account | Store | Cart
from math import *
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)])))

Diff to Previous Revision

--- revision 1 2011-11-02 22:30:10
+++ revision 2 2011-11-02 22:56:24
@@ -1,6 +1,6 @@
 from math import *
 def baseExpansion(n,c,b):
     j = 0
-    base10 = sum([pow(c,len(n)-k-1)*n[k] for k in range(0,len(n))])
+    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 [floor(base10/pow(b,j-p)) % b for p in range(1,j+1)]
+    return "".join(list(map(str,[floor(base10/pow(b,j-p)) % b for p in range(1,j+1)])))

History