A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

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.

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Python

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    only check for factors till sqrt(n)

  7. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  8. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  9. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Took me a long time, too...

  10. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  11. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  12. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.