Ask your own question, for FREE!
Computer Science 11 Online
OpenStudy (anonymous):

Wondering if anyone else has a solution for the 1st problem on the online course. The python program that finds the first 1000 prime numbers. I have a solution but apparently it is not very efficient because it is taking forever to run.

OpenStudy (anonymous):

Try this http://mathworld.wolfram.com/SieveofEratosthenes.html

OpenStudy (anonymous):

There are a bunch of efficient algorithms out there for generating prime nums, such as the Sieve of Eratosthenes, but for the first 6.00 assignment even simply caching primes you've already found would be very quick

OpenStudy (anonymous):

trial division + caching* would be fast enough.... for tiny primes like 7919 even trial division without caching is good enough :-D

OpenStudy (anonymous):

I programmed it to look for factors whos product was the number I was testing. The test started out true unless it found the two factors. That worked fine for the 1st 100 primes or so, but the 'trues per second' seem to be on the wrong end of an retricemptote approaching 0. lol

OpenStudy (anonymous):

only check for factors till sqrt(n)

OpenStudy (anonymous):

Great. If you like, you can post the code on a site like http://ideone.com and we can take a look at it.

OpenStudy (anonymous):

Maybe. I doubt it's impressive. This is the first program I've ever written.

OpenStudy (anonymous):

Took me a long time, too...

OpenStudy (anonymous):

That's okay; the first time I tried out 6.00, it took me ages to get used to it.

OpenStudy (anonymous):

Turns out I hadn't watched the lecture that spelled this out yet. Light bulbs!!! I redid it and it runs in about 10 seconds now. I learned a lot messing around though.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Countless7Echos: Ah trying out the whole T.V girl drawing :p (I love drawing eyes)
51 minutes ago 8 Replies 5 Medals
kaelynw: starting to draw a hand
2 days ago 16 Replies 2 Medals
Twaylor: Rate it :D (Took 2 days)
2 days ago 7 Replies 0 Medals
XShawtyX: Art, Short Writing Assignment: Imagining Landscapes
4 hours ago 7 Replies 1 Medal
XShawtyX: Chemistry, Help ud83dude4fud83cudffe
3 days ago 13 Replies 1 Medal
kaelynw: tried a lil smt, the arm is off but i like the other stuff
3 days ago 27 Replies 3 Medals
kaelynw: art igg
3 days ago 14 Replies 1 Medal
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!