A community for students. Sign up today!
Here's the question you clicked on:
 0 viewing
 2 years ago
Hello, can someone help me with my code about Ps2 Diophantine equations? I am stuck at the problem 4. When I run my code, it just keeps going on and on and never gives me any output. I have to press ctrl+c to stop. Here is my code: http://bpaste.net/show/53890/ I cannot figure out what is wrong. Can somebody help me with my code? Thank you.
 2 years ago
Hello, can someone help me with my code about Ps2 Diophantine equations? I am stuck at the problem 4. When I run my code, it just keeps going on and on and never gives me any output. I have to press ctrl+c to stop. Here is my code: http://bpaste.net/show/53890/ I cannot figure out what is wrong. Can somebody help me with my code? Thank you.

This Question is Closed

snark
 2 years ago
Best ResponseYou've already chosen the best response.1the code is ok  try putting a print(a,b,c,n) before the break statement. the break only exits the bottom loop, for c, but continues for a and for b. test it with n in range(10), for example, and x=1, y=2, z=3. you may want to print solutions rather than bestSoFar, but play with it.

rsmith6559
 2 years ago
Best ResponseYou've already chosen the best response.0Your code is probably running just fine. The trouble is that with 4 nested loops, each going up to 200, you're doing somewhere in the area of 200**4 iterations. That takes a while, quite possibly hours, to run. This is something to keep in mind when your designing your algorithm.

xichen
 2 years ago
Best ResponseYou've already chosen the best response.0Thank you, guys. Yes, my code is, indeed, running fine. Can I ask whether there is a way of break out all nested loops? I can only think of using this 4 nested loops to solve this problem set. Is there any other efficient way? Some hints?

snark
 2 years ago
Best ResponseYou've already chosen the best response.1try found = False for a in range(n): if found: break for b... if found: break for c..... if <condition> : do stuff found = True break

snark
 2 years ago
Best ResponseYou've already chosen the best response.1you can make it somewhat more efficient: for a in range(n): if a*x > n: # adding more won't help break for b in range(n): if a*x + b*x > n: break for c....
Ask your own question
Ask a QuestionFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.