r/projecteuler • u/AdeptIntroduction983 • Sep 13 '26
How can I improve my code for #3?
https://projecteuler.net/thread=3;page=8#456965Link to my post on the forum since I don't know if I am allowed to post it on here. I don't know how I got the solution the first time since now when I run it. Nothing happens when I use 600851475143, it works fine with smaller numbers like the one they used in the example though.
Edit: It does work it just takes a long time.
1
Upvotes
1
u/pintann Sep 13 '26 edited Sep 13 '26
For the problem specifically, take a look at the overview pdf linked from the problem
On general programming I would advise you to avoid using flags to control loop termination; instead use
break,continue,returnwhere appropriate.Global variables in general are footgun: They allow you to causally link distant pieces of code (which is powerful!). But this prevents the reader from reasoning locally about your code. Local reasoning requires the reader to keep track of fewer things, so keep variable scopes as small as possible.