How to solve diophantine problems?
Bengt Richter
bokr at oz.net
Tue May 14 16:01:25 EDT 2002
More information about the Python-list mailing list
Tue May 14 16:01:25 EDT 2002
- Previous message (by thread): How to solve diophantine problems?
- Next message (by thread): How to solve diophantine problems?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, 14 May 2002 20:37:44 +0800, "Joshua, Y.J. Lai" <g893404 at oz.nthu.edu.tw> wrote: > >"Cameron Laird" <claird at starbase.neosoft.com> wrote in message >news:EF9D274DA8540EF1.D12AA7084B83AAA2.1A9250647A55D036 at lp.airnews.net... >> In article <TQXD8.31658$Po6.14894 at rwcrnsc52.ops.asp.att.net>, >> Emile van Sebille <emile at fenx.com> wrote: >> >Joshua, Y.J. Lai >> >> I can roughly solve the diophantine problem by using a nest loop >> > >> >I'm not familiar with the "diophantine problem" and didn't, in a quick >> >look, spot anything obvious to me stating it. >> . >> . >> . >> Rough translation: a solution in integers (to >> a system of polynomial equations and constraints). > >Thank you for your precise explanation. The problem now I suffer is how can >I write a new checking loop >instead of using two FOR LOOPs as nest loop. I am really interested in that. >I will be very grateful if anyone of you can give me some hints. > This has nested loops, but they work a bit differently. You can just let it run until you get tired of waiting ;-) >>> 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 ... >>> def dioh(): ... x=xt=xp=y=0 # t for triangle, p for pyramid ... while 1: ... x += 1 ... xt += x ... xp += xt ... while xp>0: ... y += 1 ... xp -= y ... if xp==0: ... print "\rx = %d and y = %d , number = %d" % (x,y,td(x)) ... if not x % 1000: ... print "\rx = %d and y = %d , n(x) = %d, n(y) = %d" % (x,y,td(x),tri(y)), ... >>> dioh() x = 1 and y = 1 , number = 1 x = 3 and y = 4 , number = 10 x = 8 and y = 15 , number = 120 x = 20 and y = 55 , number = 1540 x = 34 and y = 119 , number = 7140 x = 78000 and y = 12577364 , n(x) = 79095042026000, n(y) = 79095048882930 Traceback (most recent call last): File "<stdin>", line 1, in ? File "<stdin>", line 7, in dioh KeyboardInterrupt The last line just keeps getting overwritten at every even thousand balls on the tetrahedron edge, until there's a valid output with td(x)==tri(y) overwriting it and advancing to the next line. Regards, Bengt Richter
- Previous message (by thread): How to solve diophantine problems?
- Next message (by thread): How to solve diophantine problems?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list