def change_of_base(n, b):
if n == 0:
return [0]
digits = []
while n > 0:
rem = n % b
digits.append(rem)
n = n // b
return digits[::-1]
change_of_base(1344, 6)
def test_f(x):
return x**5 + 13 * x**4 + 99000 * x**2 + 21
def format_output(coefs):
out = ""
for i in range(len(coefs)):
if coefs[i] == 0:
pass
else:
out += "{}x^{} + ".format(coefs[i], len(coefs) - i - 1)
return out[:-3]
def guess_f(f):
b = f(1)
c = f(b + 1)
coefs = change_of_base(c, b + 1)
return format_output(coefs)
guess_f(test_f)
def guess_from_points(b, c):
coefs = change_of_base(c, b+1)
return format_output(coefs)
guess_from_points(10, 1127390)
guess_f(lambda x: x**10000 + 10000 * x**99 + 23)