Re: [Tutor] Prime Factorization Tool

2011-12-04 Thread Lie Ryan
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

Re: [Tutor] Prime Factorization Tool

2011-12-01 Thread Steven D'Aprano
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

Re: [Tutor] Prime Factorization Tool

2011-12-01 Thread Robert Sjoblom
> 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

Re: [Tutor] Prime Factorization Tool

2011-12-01 Thread Steven D'Aprano
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

Re: [Tutor] Prime Factorization Tool

2011-12-01 Thread Robert Sjoblom
> 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

Re: [Tutor] Prime Factorization Tool

2011-12-01 Thread Robert Sjoblom
> 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

Re: [Tutor] Prime Factorization Tool

2011-12-01 Thread Steven D'Aprano
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.

Re: [Tutor] Prime Factorization Tool

2011-12-01 Thread Wayne Werner
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

[Tutor] Prime Factorization Tool

2011-12-01 Thread Robert Sjoblom
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