On 12/02/2011 12:15 AM, Robert Sjoblom wrote:
So I've recently started poking at the Project Euler site, because I
feel that I need to practice writing code. For those of you interested
in solving the problems on your own I advice you to not read this, as
it will spoil the solution.
Problem 3 is
Robert Sjoblom wrote:
So you can roughly double the speed of your function by skipping even
numbers other than two. Remember that 2 itself is prime, but any other
multiple of 2 is not. Take that test outside of the loop, and then loop over
every second number starting with 3.
So, if I understo
> So you can roughly double the speed of your function by skipping even
> numbers other than two. Remember that 2 itself is prime, but any other
> multiple of 2 is not. Take that test outside of the loop, and then loop over
> every second number starting with 3.
>
So, if I understood this right, m
Robert Sjoblom wrote:
from math import sqrt
def isprime(n, factor):
if n == 1:
return False
for x in range(2, round(sqrt(n))):
if n % x == 0:
return False
else:
return True
factor is not used in the isprime function; get rid of it.
A bug in you
> from math import sqrt
>
> def isprime(n, factor):
> if n == 1:
> return False
> for x in range(2, round(sqrt(n))):
Ooops, this should obviously read
for x in range(factor, round(sqrt(n))):
best regards,
Robert S.
___
Tutor maillist - Tut
> Well, there are really only a couple of optimizations that you could make.
> That's the nice (bad?) thing about primes - you really only *can* brute
> force a solution. That's why nice things like encryption exist.
Yes, I know that; perhaps I was unclear but my issues with brute force
are for sol
Wayne Werner wrote:
[...]
Well, there are really only a couple of optimizations that you could make.
That's the nice (bad?) thing about primes - you really only *can* brute
force a solution. That's why nice things like encryption exist.
Brute force is a little strong, but not far from the mark.
On Thu, Dec 1, 2011 at 7:15 AM, Robert Sjoblom wrote:
> So I've recently started poking at the Project Euler site, because I
> feel that I need to practice writing code. For those of you interested
> in solving the problems on your own I advice you to not read this, as
> it will spoil the solution
So I've recently started poking at the Project Euler site, because I
feel that I need to practice writing code. For those of you interested
in solving the problems on your own I advice you to not read this, as
it will spoil the solution.
Problem 3 is this:
The prime factors of 13195 are 5, 7, 13 a