[Tutor] List Splicing
Robert Berman
bermanrl at cfl.rr.com
Thu Jun 18 01:48:46 CEST 2009
Emile,
Thank your for your comments. I do have a list running from 0-1000001.
Yes, it is true, I only needed 0 - 100000 and yes I will change it.
However, if you use primearray as a sieve of all primes 2-1000000 you
will see it works quite well. Printing a range, say primearray[21]
through primearray[50] will give you all prime numbers between 21 and
50.
23
29
31
37
41
43
47
73000 to 99,123 works nicely, too. I did, in the beginning use a list of
100 (actually (101) and that worked well so thank you for corroborating
the approach.
Another question I will ask after this one is resolved involves the
methodology I use to find primes well over one million.
However, for the time being, can you perhaps share some suggestions on
list splicing?
Thank you for your assistance.
Robert
On Wed, 2009-06-17 at 15:25 -0700, Emile van Sebille wrote:
> On 6/17/2009 3:03 PM Robert Berman said...
> > Greetings,
> >
> > I am working on a 'simple' algorithm to solve the problem called PRIME1
> > explained at http://www.spoj.pl/problems/PRIME1/.
> >
> > I do have an algorithm based on the Sieve of Eratosthenes and it does
> > work as I am failing the project not because of a computational error
> > but because of the dreaded TLE (time limit exceeded) designator. I have
> > determined there are at least 3 areas for improvement. The first is
> > within my code where I am creating a list of the first million primes.
>
> It looks more like it creates a list 1000001 in length where the
> non-zero numbers in that list are primes. I'd try BuildSieve(100) until
> BuildSieve was returning just primes.
>
> Or, are you trying to create a list of the primes under 1000000?
>
> Optimization should proceed once you've got it working.
>
> Emie
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list