Re: Prime testing [was Re: My backwards logic]

2014-09-07 Thread Dan Stromberg
On Sun, Sep 7, 2014 at 11:53 AM, Peter Pearson wrote: > On Sat, 6 Sep 2014 12:53:16 +0200, Manolo Martínez wrote: >> On 09/06/14 at 08:38pm, Steven D'Aprano wrote: >>> But even that's not how the specialists do it. If you want to check whether >>> (say) 2**3000+1 is prime, you don't want to use tr

Re: Prime testing [was Re: My backwards logic]

2014-09-07 Thread Manolo Martínez
On 09/07/14 at 06:53pm, Peter Pearson wrote: > On Sat, 6 Sep 2014 12:53:16 +0200, Manolo Martínez wrote: > > On 09/06/14 at 08:38pm, Steven D'Aprano wrote: > >> But even that's not how the specialists do it. If you want to check whether > >> (say) 2**3000+1 is prime, you don't want to use trial div

Re: Prime testing [was Re: My backwards logic]

2014-09-07 Thread Peter Pearson
On Sat, 6 Sep 2014 12:53:16 +0200, Manolo Martínez wrote: > On 09/06/14 at 08:38pm, Steven D'Aprano wrote: >> But even that's not how the specialists do it. If you want to check whether >> (say) 2**3000+1 is prime, you don't want to use trial division at all... > > When I was interested in these th

Re: Prime testing [was Re: My backwards logic]

2014-09-06 Thread Manolo Martínez
On 09/06/14 at 08:38pm, Steven D'Aprano wrote: > But even that's not how the specialists do it. If you want to check whether > (say) 2**3000+1 is prime, you don't want to use trial division at all... When I was interested in these things, specialists would use the [number field sieve](https://en.w

Re: Prime testing [was Re: My backwards logic]

2014-09-06 Thread Chris Angelico
On Sat, Sep 6, 2014 at 8:38 PM, Steven D'Aprano wrote: > 3, 5, 7, 9 is a waste of time, 11, 13, 15 is a waste of time, ... I love this sequence. ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Prime testing [was Re: My backwards logic]

2014-09-06 Thread Steven D'Aprano
Denis McMahon wrote: > Note also that when searching for factors of a number n, and starting at > 2, you can generally stop at somewhere around n/3, The largest factor of N you actually need to check is sqrt(n). Every factor of n below the square root has a corresponding factor above it, e.g. if

Re: My backwards logic

2014-09-06 Thread Denis McMahon
On Fri, 05 Sep 2014 12:48:56 -0400, Seymore4Head wrote: > But, what this instructions want printed is "This is a prime number" > So how to I use this code logic NOT print (not prime) and have the logic > print "This number is prime" This is an algorithmic question, not a python question, so the a

Re: My backwards logic

2014-09-06 Thread Mark Lawrence
This is top posted and makes it extremely difficult to follow long threads with many replies. This is heavily frowned upon here. On 06/09/2014 02:54, Juan Christian wrote: @Mark Lawrence: Sorry to ask, but what do you mean by "don't top post here, thanks.", I'm not familiar with mailing lists,

Re: Posting style: interleaved responses (was: My backwards logic)

2014-09-05 Thread Zachary Ware
On Fri, Sep 5, 2014 at 10:06 PM, Juan Christian wrote: > On Fri, Sep 5, 2014 at 11:37 PM, Ben Finney > wrote: >> >> Juan Christian writes: >> >> > @Mark Lawrence: Sorry to ask, but what do you mean by "don't top post >> > here, thanks.", I'm not familiar with mailing lists, so I may be doing >>

Re: My backwards logic

2014-09-05 Thread Dave Angel
Seymore4Head Wrote in message: > On Fri, 05 Sep 2014 12:48:56 -0400, Seymore4Head > wrote: > > > If you start with the list [3,5,7] and step through the list of all > remaining odd numbers (step 2), and start appending numbers that won't > divide by numbers already appended in the list, that w

Re: Posting style: interleaved responses (was: My backwards logic)

2014-09-05 Thread Juan Christian
On Fri, Sep 5, 2014 at 11:37 PM, Ben Finney wrote: > Juan Christian writes: > > > @Mark Lawrence: Sorry to ask, but what do you mean by "don't top post > > here, thanks.", I'm not familiar with mailing lists, so I may be doing > > something wrong and I don't know. > > Please post your responses

Posting style: interleaved responses (was: My backwards logic)

2014-09-05 Thread Ben Finney
Juan Christian writes: > @Mark Lawrence: Sorry to ask, but what do you mean by "don't top post > here, thanks.", I'm not familiar with mailing lists, so I may be doing > something wrong and I don't know. Please post your responses interleaved with the quoted material to which you're responding.

Re: My backwards logic

2014-09-05 Thread Rustom Mody
On Saturday, September 6, 2014 7:25:10 AM UTC+5:30, Juan Christian wrote: > @Mark Lawrence: Sorry to ask, but what do you mean by "don't top post here, > thanks.", I'm not familiar with mailing lists, so I may be doing something > wrong and I don't know. Maybe better to say use this http://en.w

Re: My backwards logic

2014-09-05 Thread Juan Christian
@Mark Lawrence: Sorry to ask, but what do you mean by "don't top post here, thanks.", I'm not familiar with mailing lists, so I may be doing something wrong and I don't know. On Fri, Sep 5, 2014 at 4:54 PM, Mark Lawrence wrote: > On 05/09/2014 20:34, Juan Christian wrote: > >> What's [snip] ??

Re: My backwards logic

2014-09-05 Thread Rustom Mody
On Saturday, September 6, 2014 1:37:57 AM UTC+5:30, Paul Rubin wrote: > Juan Christian writes: > > I made this code just for fun and learning, it's working, but would > > this be a good approach? Thanks. ... > > ** ** for number in range(start, stop + 1): > > ** ** ** ** divisors = [(number %

Re: My backwards logic

2014-09-05 Thread Chris Angelico
On Sat, Sep 6, 2014 at 3:44 AM, Seymore4Head wrote: > BTW since I am getting no grade, I much prefer the answer than a hint. > The best hint IMO is to tell me how you would do it. But for your own learning, it's still better for you to do things yourself. Giving you the answer doesn't teach you n

Re: My backwards logic

2014-09-05 Thread Seymore4Head
On Fri, 5 Sep 2014 16:35:18 -0600, Ian Kelly wrote: >On Fri, Sep 5, 2014 at 3:49 PM, Seymore4Head > wrote: >> I am sure this has already been done, but after it was pointed out >> that you don't need to test for any number that multiplies by 2 it >> made me think again. >> >> If you start with th

Re: My backwards logic

2014-09-05 Thread Seymore4Head
On Fri, 5 Sep 2014 15:14:41 -0700, Chris Kaynor wrote: >On Fri, Sep 5, 2014 at 2:49 PM, Seymore4Head >wrote: > >> On Fri, 05 Sep 2014 12:48:56 -0400, Seymore4Head >> wrote: >> >> >I'm still doing practice problems. I haven't heard from the library >> >on any of the books I have requested. >> >

Re: My backwards logic

2014-09-05 Thread Ian Kelly
On Fri, Sep 5, 2014 at 3:49 PM, Seymore4Head wrote: > I am sure this has already been done, but after it was pointed out > that you don't need to test for any number that multiplies by 2 it > made me think again. > > If you start with the list [3,5,7] and step through the list of all > remaining o

Re: My backwards logic

2014-09-05 Thread Chris Kaynor
On Fri, Sep 5, 2014 at 2:49 PM, Seymore4Head wrote: > On Fri, 05 Sep 2014 12:48:56 -0400, Seymore4Head > wrote: > > >I'm still doing practice problems. I haven't heard from the library > >on any of the books I have requested. > > > > > http://www.practicepython.org/exercise/2014/04/16/11-check-

Re: My backwards logic

2014-09-05 Thread Seymore4Head
On Fri, 05 Sep 2014 12:48:56 -0400, Seymore4Head wrote: >I'm still doing practice problems. I haven't heard from the library >on any of the books I have requested. > >http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html > >This is not a hard problem, but it got me

Re: My backwards logic

2014-09-05 Thread Ian Kelly
On Fri, Sep 5, 2014 at 11:44 AM, Seymore4Head wrote: > BTW since I am getting no grade, I much prefer the answer than a hint. > The best hint IMO is to tell me how you would do it. from math import ceil, sqrt def is_prime(n): if n < 2: return False if n % 2 == 0: return n

Re: My backwards logic

2014-09-05 Thread Paul Rubin
Juan Christian writes: > I made this code just for fun and learning, it's working, but would > this be a good approach? Thanks. ... > ** ** for number in range(start, stop + 1): > ** ** ** ** divisors = [(number % x) for x in range(1, number + 1)] > ** ** ** ** ** ** print("{n} prime? {r}".fo

Re: My backwards logic

2014-09-05 Thread Mark Lawrence
On 05/09/2014 20:34, Juan Christian wrote: What's [snip] ?? As in cut out or chopped out such that some of the original text has been removed. And please don't top post here, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language.

Re: My backwards logic

2014-09-05 Thread Juan Christian
What's [snip] ?? On Fri, Sep 5, 2014 at 3:48 PM, MRAB wrote: > On 2014-09-05 18:35, Juan Christian wrote: > >> I made this code just for fun and learning, it's working, but would this >> be a good approach? Thanks. >> >> import sys >> >> >> def prime_checker(start = 1, stop = 1): >> > > In Pyth

Re: My backwards logic

2014-09-05 Thread MRAB
On 2014-09-05 18:35, Juan Christian wrote: I made this code just for fun and learning, it's working, but would this be a good approach? Thanks. import sys def prime_checker(start = 1, stop = 1): In Python, the standard is to use a half-open range. for number in range(start, stop + 1):

Re: My backwards logic

2014-09-05 Thread Ethan Furman
On 09/05/2014 10:17 AM, Ian Kelly wrote: I would not worry about the else clause as a beginner, as it's relatively unique to Python and tends to be somewhat confusing. Use a flag or refactor the function instead. I don't disagree with this, but early exposure to "for..else is for search loops"

Re: My backwards logic

2014-09-05 Thread Chris Kaynor
On Fri, Sep 5, 2014 at 10:44 AM, Seymore4Head wrote: > On Fri, 05 Sep 2014 10:08:18 -0700, Ethan Furman > wrote: > > >On 09/05/2014 09:48 AM, Seymore4Head wrote: > >> I'm still doing practice problems. I haven't heard from the library > >> on any of the books I have requested. > >> > >> > http:

Re: My backwards logic

2014-09-05 Thread Seymore4Head
On Fri, 05 Sep 2014 10:08:18 -0700, Ethan Furman wrote: >On 09/05/2014 09:48 AM, Seymore4Head wrote: >> I'm still doing practice problems. I haven't heard from the library >> on any of the books I have requested. >> >> http://www.practicepython.org/exercise/2014/04/16/11-check-primality-function

Re: My backwards logic

2014-09-05 Thread Juan Christian
I made this code just for fun and learning, it's working, but would this be a good approach? Thanks. import sys def prime_checker(start = 1, stop = 1): for number in range(start, stop + 1): divisors = [(number % x) for x in range(1, number + 1)] print("{n} prime? {r}".format(n = number, r = (div

Re: My backwards logic

2014-09-05 Thread Ian Kelly
On Fri, Sep 5, 2014 at 11:08 AM, Ethan Furman wrote: > Python's 'for' loop has a handy 'else' extension which is perfect for the > search-type of 'for' loop: > >while True: > a=random.randrange(1,8) > print (a) > for x in range(2,a): > if a%x==0: >

Re: My backwards logic

2014-09-05 Thread John Gordon
In <1enj0att6bkrnvb81rhma5dbuk3h28a...@4ax.com> Seymore4Head writes: > I'm still doing practice problems. I haven't heard from the library > on any of the books I have requested. > http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html > This is not a hard problem

Re: My backwards logic

2014-09-05 Thread Chris Kaynor
On Fri, Sep 5, 2014 at 9:48 AM, Seymore4Head wrote: > I'm still doing practice problems. I haven't heard from the library > on any of the books I have requested. > > > http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html > > This is not a hard problem, but it got m

Re: My backwards logic

2014-09-05 Thread Ethan Furman
On 09/05/2014 09:48 AM, Seymore4Head wrote: I'm still doing practice problems. I haven't heard from the library on any of the books I have requested. http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html This is not a hard problem, but it got me to thinking a litt

Re: My backwards logic

2014-09-05 Thread Bob Gailer
Bob gailer On Sep 5, 2014 12:51 PM, "Seymore4Head" wrote: > > I'm still doing practice problems. I haven't heard from the library > on any of the books I have requested. > > http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html > > This is not a hard problem, but it

Re: My backwards logic

2014-09-05 Thread MRAB
On 2014-09-05 17:48, Seymore4Head wrote: I'm still doing practice problems. I haven't heard from the library on any of the books I have requested. http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html This is not a hard problem, but it got me to thinking a little.

My backwards logic

2014-09-05 Thread Seymore4Head
I'm still doing practice problems. I haven't heard from the library on any of the books I have requested. http://www.practicepython.org/exercise/2014/04/16/11-check-primality-functions.html This is not a hard problem, but it got me to thinking a little. A prime number will divide by one and its