A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 4 years ago
I'm having trouble with ps1 problem 2. The easiest/best way to do this seems to be:
1. Take the list of primes I made in the first problem
2. log all of those primes
3. put the logs of all those primes in a list
4. take the logs list and calculate the sum of the numbers
5. print the sum
6. sum/n to calculate the ratio
7. print the ratio
Now putting that into code is a different story. I'm thinking a for statement would be best. How to I use the for statement on my previous list of primes? How do I do logs on that list of primes and stick all of those logs into a list?
anonymous
 4 years ago
I'm having trouble with ps1 problem 2. The easiest/best way to do this seems to be: 1. Take the list of primes I made in the first problem 2. log all of those primes 3. put the logs of all those primes in a list 4. take the logs list and calculate the sum of the numbers 5. print the sum 6. sum/n to calculate the ratio 7. print the ratio Now putting that into code is a different story. I'm thinking a for statement would be best. How to I use the for statement on my previous list of primes? How do I do logs on that list of primes and stick all of those logs into a list?

This Question is Closed

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0I'm also new to this class, and just went through this chapter yesterday. You're on the right track, you just need to learn the syntax. Take a look at my attachment and see if it helps. Let me know if you want me to get more specific.

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0Sorry, when you import math, you still need to address log as math.log(myVariable)

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0Strictly speaking, you don't need to keep a list of primes to solve this problem. Here is some pseudocode: 1. Write a loop such that you stay in the loop until you have found the 1000th prime 2 Let "test_num" be the number you are testing for primality 3. Let "prime_count" represent the nth prime number you have found (e.g. when test_num = 29, prime_count should become 10 since that's the 10th prime) 4. Initialize a variable call "log_sum" which will store the sum of the log of the prime numbers 5. Determine if test_num is prime 6. If test_num is prime (e.g. 3), then take it's log and add it to log_sum (e.g. log_sum+=log(test_num) 7. When prime_count reaches 1000 then you break out of the loop

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0But suppose you did want to keep a list of primes for the hell of it. It's actually not a bad way of checking your code to see you are correctly generating the prime numbers: 1. Initialize an empty list, calling it let's say primes=[ ] 2. As you come across a prime, append it to the list e.g. primes.append(test_num) You should get a list of primes like so [2,3,5,7,11,....]

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0I actually used the list of prime numbers to find new prime numbers more efficiently. Instead of trying to divide all numbers into n where numbers < n, I only used prime numbers. It doesn't seem to make a big difference on the first 1000 primes, but above that it runs a little smoother

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0@makeavellious. For discovering larger primes having an inventory of base primes to test is a much better algorithm. For that one can use a list. But for retrieving the 1000th prime it won't make much of a difference.

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0faster algorithm than dividing by num< n is to use num < sqrt(n)
Ask your own question
Sign UpFind more explanations on OpenStudy
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
 Engagement 19 Mad Hatter
 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.