anonymous
  • anonymous
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?
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
I'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.
1 Attachment
anonymous
  • anonymous
Sorry, when you import math, you still need to address log as math.log(myVariable)
anonymous
  • anonymous
Strictly speaking, you don't need to keep a list of primes to solve this problem. Here is some pseudo-code: 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

Looking for something else?

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

More answers

anonymous
  • anonymous
But 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
  • anonymous
I 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
  • anonymous
@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
  • anonymous
faster algorithm than dividing by num< n is to use num < sqrt(n)

Looking for something else?

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