Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Dave Angel
On 01/23/2012 05:55 PM, Steven D'Aprano wrote: On Mon, Jan 23, 2012 at 10:01:33PM +, Alan Gauld wrote: Just to be clear this has nothing to do with Python. It doesn't matter what programming language you choose there is not a PC on Earth that can do what you want using the technique you are

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Marc Tompkins
On Mon, Jan 23, 2012 at 8:03 PM, Dave Angel wrote: > On 01/23/2012 10:31 PM, Marc Tompkins wrote: > >> On Mon, Jan 23, 2012 at 12:08 PM, Shreesh bhat** >> wrote: >> >> No,i meant sum of digits is prime and also sum of square of digits is >>> prime. >>> E.g: 23 is lucky cos >>> 2+3=>5 (prime) >>>

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Dave Angel
On 01/23/2012 10:31 PM, Marc Tompkins wrote: On Mon, Jan 23, 2012 at 12:08 PM, Shreesh bhatwrote: No,i meant sum of digits is prime and also sum of square of digits is prime. E.g: 23 is lucky cos 2+3=>5 (prime) 2**2+3**2 => 4+9 => 13 (prime) Thanks for the clarification - or I should say "c

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Marc Tompkins
On Mon, Jan 23, 2012 at 12:08 PM, Shreesh bhat wrote: > No,i meant sum of digits is prime and also sum of square of digits is > prime. > E.g: 23 is lucky cos > 2+3=>5 (prime) > 2**2+3**2 => 4+9 => 13 (prime) > Thanks for the clarification - or I should say "correction", since "sum of square of di

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Walter Prins
Hi On 23 January 2012 22:55, Steven D'Aprano wrote: > > > > >Can i work around that way in python or should i come up with a new > > >algorithm? > > > > You definitely need a fundamentally different algorithm. > > I expect that this is some question from one of those annoying > websites that offe

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Steven D'Aprano
On Mon, Jan 23, 2012 at 10:01:33PM +, Alan Gauld wrote: > Just to be clear this has nothing to do with Python. It doesn't matter > what programming language you choose there is not a PC on Earth that can > do what you want using the technique you are using in 16 seconds. I don't believe tha

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Alan Gauld
On 23/01/12 18:51, Shreesh bhat wrote: Since i m new to Python.I dont know all its recipes and tricks inlvolved to "charm-the-snake". So can i improve the islucky method more than what i mentioned before? Not by enough to meet your constraints. Just to be clear this has nothing to do with Pyt

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Shreesh bhat
No,i meant sum of digits is prime and also sum of square of digits is prime. E.g: 23 is lucky cos 2+3=>5 (prime) 2**2+3**2 => 4+9 => 13 (prime) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/m

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Marc Tompkins
On Mon, Jan 23, 2012 at 11:42 AM, Marc Tompkins wrote: > On Mon, Jan 23, 2012 at 10:51 AM, Shreesh bhat wrote: > >> I have given the definition of lucky numbers and constraints involved at >> the starting of the thread. >> when a number's sum of digits and square of sum of digits is prime,it is >>

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Marc Tompkins
On Mon, Jan 23, 2012 at 10:51 AM, Shreesh bhat wrote: > I have given the definition of lucky numbers and constraints involved at > the starting of the thread. > when a number's sum of digits and square of sum of digits is prime,it is > called lucky. > Just to clarify: do you mean "(sum of digits)

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Shreesh bhat
I have given the definition of lucky numbers and constraints involved at the starting of the thread. when a number's sum of digits and square of sum of digits is prime,it is called lucky. I already tried generating prime numbers using sieve of atkin algorithm rather than doing primality test. Effi

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Dave Angel
On 01/23/2012 08:13 AM, Shreesh bhat wrote: I tried optimizing everything all things you guys pointed out and still its orders of magnitude away from the expected result. The program should check the islucky condition between range of (1,10**18) numbers and iterate over that 10**5 times. This

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Dave Angel
On 01/23/2012 01:20 PM, Alan Gauld wrote: On 23/01/12 13:13, Shreesh bhat wrote: I tried optimizing everything all things you guys pointed out and still its orders of magnitude away from the expected result. That's what I suspected. It means the fundamental approach of testing every number ca

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Alan Gauld
On 23/01/12 13:13, Shreesh bhat wrote: I tried optimizing everything all things you guys pointed out and still its orders of magnitude away from the expected result. That's what I suspected. It means the fundamental approach of testing every number can probably never work. Which approach sh

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Steven D'Aprano
On Mon, Jan 23, 2012 at 06:43:50PM +0530, Shreesh bhat wrote: > The program should check the islucky condition between range of (1,10**18) > numbers and iterate over that 10**5 times. How is the islucky condition defined? The only version I have found is based on something quite similar to prim

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Peter Otten
Shreesh bhat wrote: > I tried optimizing everything all things you guys pointed out and still > its orders of magnitude away from the expected result. > The program should check the islucky condition between range of (1,10**18) > numbers and iterate over that 10**5 times. > This program slows down

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Shreesh bhat
I tried optimizing everything all things you guys pointed out and still its orders of magnitude away from the expected result. The program should check the islucky condition between range of (1,10**18) numbers and iterate over that 10**5 times. This program slows down more than 16 secs at (1,10**8)

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Alan Gauld
On 23/01/12 06:10, Shreesh bhat wrote: def sieve(maxi): primes = range(2,maxi+1) You can reduce the size of primes by only storing the odd numbers. range takes a third parameter that sets the stepsize, you cxan use that to skip evens... for i in primes: j = 2 you can then start

Re: [Tutor] OverflowError in lucky numbers script

2012-01-23 Thread Peter Otten
Shreesh bhat wrote: > Thank you all for helping me understand the overflow error. > I m a newbie on mailing lists.I apologize for my errors. > Program: [snip code] > The program is executing correctly but it has to execute 16 seconds for > the constraints. > I have optimized the way i sum up dig

Re: [Tutor] OverflowError in lucky numbers script

2012-01-22 Thread Blockheads Oi Oi
On 23/01/2012 06:15, Shreesh bhat wrote: Calculating the table is fast. I think either my luckiness test (where i find the sum of all digits and sum of squares of all digits of a large number) or generating numbers is slow. Don't think, know :) Tools like the profile or timeit modules are ther

[Tutor] OverflowError in lucky numbers script

2012-01-22 Thread Shreesh bhat
Thank you all for helping me understand the overflow error. I m a newbie on mailing lists.I apologize for my errors. Program: def sieve(maxi): primes = range(2,maxi+1) for i in primes: j = 2 while i * j <= primes[-1]: if i * j in primes: primes.remove(i*j) j += 1

Re: [Tutor] OverflowError in lucky numbers script

2012-01-22 Thread Shreesh bhat
Calculating the table is fast. I think either my luckiness test (where i find the sum of all digits and sum of squares of all digits of a large number) or generating numbers is slow. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscri

Re: [Tutor] OverflowError in lucky numbers script

2012-01-22 Thread Dave Angel
You sent me this message privately, instead of on the list (use Reply-All in most mail programs). Two problems with that: 1) nobody else gets to help 2) I don't give private help, except as a contractor. On 01/22/2012 12:44 PM, Shreesh bhat wrote: *Lucky numbers:* def sieve(maxi): prime

Re: [Tutor] OverflowError in lucky numbers script

2012-01-22 Thread Alan Gauld
On 22/01/12 11:37, Shreesh bhat wrote: Steven wrote: " Scale your numbers from time to time, to avoid them getting too big " What does this mean? It could be done in various ways but one simple example is, low = 100 hi = 110 for n in range(low,hi): ... code uses n ... c

Re: [Tutor] OverflowError in lucky numbers script

2012-01-22 Thread Dave Angel
On 01/22/2012 06:37 AM, Shreesh bhat wrote: I m using Python 2.7 Steven wrote: " Scale your numbers from time to time, to avoid them getting too big" What does this mean? inp refers to the sample input test case I have given at first.Its a string containing two numbers, The program has to handle

Re: [Tutor] OverflowError in lucky numbers script

2012-01-22 Thread Peter Otten
Shreesh bhat wrote: > I m using Python 2.7 > Steven wrote: > " Scale your numbers from time to time, to avoid them getting too big " > What does this mean? > > inp refers to the sample input test case I have given at first.Its a > string containing two numbers, > The program has to handle large n

[Tutor] OverflowError in lucky numbers script

2012-01-22 Thread Shreesh bhat
I m using Python 2.7 Steven wrote: " Scale your numbers from time to time, to avoid them getting too big " What does this mean? inp refers to the sample input test case I have given at first.Its a string containing two numbers, The program has to handle large numbers till 10**18 and also has to ex

[Tutor] OverflowError in lucky numbers script, was Re: Tutor Digest, Vol 95, Issue 55

2012-01-22 Thread Peter Otten
Shreesh bhat wrote: > *Lucky Numbers* > A number is called lucky if the sum of its digits, as well as the sum of > the squares of its digits is a prime number. How many numbers between A > and B are lucky? > Input: > The first line contains the number of test cases T. Each of the next T > lines co