sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

Paul Rubin no.email at nospam.invalid
Tue Jun 21 22:09:36 EDT 2011


John Salerno <johnjsal at gmail.com> writes:
> It's frustrating because I have the Python right, but I'm getting
> stuck on the math....
> "What is the smallest positive number that is evenly divisible by all
> of the numbers from 1 to 20?"

The answer is lcm [1,2,3, ... 20].  You can figure out how to implement
lcm.

The Euler problems are not really programming exercises.  They are
exercises in math and algorithms.  Quite a lot of them involve thinking
clever and fast ways to do stuff that would be trivial (but too slow) by
brute force.  In general, once you figure out the right algorithm,
writing the code is easy.  But you have to be fairly mathematically
attuned, to have any chance of spotting the algorithm.

If you want programming exercises that are less mathematical, there are
some nice ones at rubyquiz.com.  They are intended for Ruby but of
course you can solve them in Python.



More information about the Python-list mailing list