How to solve diophantine problems?

Joshua, Y.J. Lai g893404 at oz.nthu.edu.tw
Mon May 13 16:40:34 EDT 2002


Dear everyone:

I can roughly solve the diophantine problem by using a nest loop
ex.
def td(x):
    "The number of balls used to construct a tetrahedron"
    return x*(x+1)*(x+2)/6

def tri(y):
    "The number of balls used to construct a triangle"
    return y*(y+1)/2

for x in xrange(100):
    for y in xrange(100):
        a=td(x)
        b=tri(y)
        if a==b!=0:
            print "x = %d and y = %d , number = %d" % (x,y,a)
----------------------------------------------------------------------------
-------
But if I want to limit the maximum amount of balls (k) in this question
then I will add an additional line:
k=input("Please define the Max of balls: ")
However, I do not know how to write the checking loops in this case?
Because, the x and y are uncertain now. Could anyone please kindly help me.
Thank you.







More information about the Python-list mailing list