You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

24 lines
463 B

from functools import reduce
from operator import mul
def _base(n,b):
out =[]
while n:
out.append(n%b)
n //= b
return out
def _multbase(n,bases):
out = []
if functools.reduce(mul,bases) < n:
raise ValueError("Not enough bases/not big enough")
for base in reversed(bases):
out.append(n%bases)
n //= base
if not n:
return out
def base(n,base_arg):
try:
return _multbase(n,base_arg
except ValueError:
return _base(n,base_arg)