Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

search for values in discrete range

I am trying to search for solutions to a pair of equations but only using a few values. I know which values give the possible answers and I want to skip the computation time associated with checking every single value up within an interval. I am using the simple code:

for a in srange(0,200):

 for b in srange(1,a+1):
      if (a+b).is_square() and (a^2+b^2).is_square():
           print(a,b)

which gives me the solutions I want but it computes every integer solution from 0 to 200. If I know the answers, can I search for the range like

for a in range(9,21,28,36,40,84,112,133,156,160)

and then the same as above, and it will print:

28, 21

40, 9

112, 84

156,133

160,36

Any idea how to make that work? This is not homework or anything, just doing a bit of research and I'm a new. Thanks!!

click to hide/show revision 2
None

search for values in discrete range

I am trying to search for solutions to a pair of equations but only using a few values. I know which values give the possible answers and I want to skip the computation time associated with checking every single value up within an interval. I am using the simple code:

for a in srange(0,200):

for a in srange(0,200):
     for b in srange(1,a+1):
       if (a+b).is_square() and (a^2+b^2).is_square():
            print(a,b)

which gives me the solutions I want but it computes every integer solution from 0 to 200. If I know the answers, can I search for the range like

for a in range(9,21,28,36,40,84,112,133,156,160)

and then the same as above, and it will print:

28, 21

40, 9

112, 84

156,133

160,36

Any idea how to make that work? This is not homework or anything, just doing a bit of research and I'm a new. Thanks!!