Project Euler Tips

In the first couple of problems, you can get away with attempting the most straightforward and simple solution, e.g. for problem 1 it is fine to check every possible number as the search space is only 1000 numbers. For later problems, you will need to think about reducing the scope before you attempt to solve it, otherwise solutions may take a long time to run (Project Euler suggests that no solution should take more than 1 minute to run).

Reduce the search space

Each iteration of your algorithm has a cost, therefore if you can reduce the number of iterations you will reduce the overall time. There are usually three ways to do this:

A good example of this is in problem 5. The initial search space is over 200m numbers, however by only checking every 20th number (which is all that is required), we can reduce the search space by 95%, i.e. 10m numbers.