In [2]:
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]
In [3]:
change_of_base(1344, 6)
Out[3]:
[1, 0, 1, 2, 0]
In [4]:
def test_f(x):
    return x**5 + 13 * x**4 + 99000 * x**2 + 21
In [5]:
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]
In [6]:
def guess_f(f):
    b = f(1)
    c = f(b + 1)
    
    coefs = change_of_base(c, b + 1)
    
    return format_output(coefs)
In [7]:
guess_f(test_f)
Out[7]:
'1x^5 + 13x^4 + 99000x^2 + 21x^0'
In [8]:
def guess_from_points(b, c):
    
    coefs = change_of_base(c, b+1)
    
    return format_output(coefs)
In [9]:
guess_from_points(10, 1127390)
Out[9]:
'7x^5 + 3x^1'
In [10]:
guess_f(lambda x: x**10000 + 10000 * x**99 + 23)
Out[10]:
'1x^10000 + 10000x^99 + 23x^0'
In [ ]: