In the 2nd assignment, one of the tips to generate the prime numbers was to generate all odd integers >1. Where can I store the generated list? Aren't we only allowed to use conditional statements, loops and variables?

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.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions.

A community for students.

In the 2nd assignment, one of the tips to generate the prime numbers was to generate all odd integers >1. Where can I store the generated list? Aren't we only allowed to use conditional statements, loops and variables?

MIT 6.00 Intro Computer Science (OCW)
See more answers at brainly.com
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.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

Instead of generating all odd integers, I think most people tend to only test negative integers by starting with 3 and then increasing by 2 each time. That way you only test odd numbers, but you don't have to generate a list of odd numbers at the beginning.
You have several questions rolled into one. Let's take each question in turn. 1) "Aren't we only allowed to use conditional statements, loops and variables?" You are not restricted to any particular technique as long as you solve the problem. 2) The use of the word "generate" is unfortunate. The purpose of the exercise is to check integers for primality. Since we know that the even numbers are all composite (divisible by 2) we can with one fell swoop eliminate from the test. By "generating" prime numbers the mean only check the odd numbers for primality. You can do that using whatever technique. 3) "Where can I store the generated list?" For this assignment strictly speaking you don't need to store items in a list to solve the problem. However, for troubleshooting purposes and to verify that you are coming up the right results it's helpful to build that into your program initially. Let's say that you want to store the primes as you cycle through the set of odd numbers. You could a) declare an empty list called primes; b) append to that list as you come across a prime number; primes=[ ] the loop in your program which checks to see if num is indeed a prime number; if it is append it the list that stores the set of prime numbers primes.append(num)
I believe the short answer is that generating a list is not necessary. a brute force method may simply involve taking a number "x", and then attempting to divide by an increasing number "y". You can increase the value of "y" with a loop. You can increase the value of "x" with another loop. You needn't store all of these values you are generating. For some faster methods that may take advantage of concepts that are introduced later, you may see the discussion here: http://openstudy.com/study?F1244392739431MUOV2U=_#/updates/4f1241dbe4b0a4c24f583004

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Not the answer you are looking for?

Search for more explanations.

Ask your own question