ivanidris.
net
NumPy Project Euler Problem 5
Project Euler Problem 5is one of those problems that seem hard, but turn out to be trivial after you
think about them.
In this case it is very important to use the information given to you in the
problem.
This...
More
ivanidris.
net
NumPy Project Euler Problem 5
Project Euler Problem 5is one of those problems that seem hard, but turn out to be trivial after you
think about them.
In this case it is very important to use the information given to you in the
problem.
This means using the fact that 2520 is the smallest number that can be divided by each of
the numbers from 1 to 10 without any remainder.
We can therefore limit our search to multiples of
2520.
1.
Create a divisors array
First we will create a divisors array.
We only need to divide by the numbers 11 – 20.
divisors = numpy.
arange(11, 21)
2.
Check for 0 remainder
Second make sure that all the divisions of a number by the divisors produce a 0 remainder.
We can
check for that with the NumPy all function.
numpy.
all((i % divisors) == 0)
3.
Test the solution
Eventually we will get an answer.
We need to check whether this is the correct answer.
Use the
assert_equal function from the numpy.
testing module to confirm the result.
numpy
Less