Author | Message |
---|---|
rabbott
Posts: 1649
|
Posted 11:54 Jan 25, 2019 |
On Wednesday we talked about a Python program to generate primes. I suggested variants that might or might not work. The following puts a number of variants together and tries them all.
from itertools import count
When run, the result looks like this.
Variants 0, 1, and 3 get the right answer. Variants 2 and 4 get the wrong answer. Here are some questions. 1. How, if at all, do variants 0 and 1 differ in what they compute? 2. Variants 0 and 2 look like they are logically equivalent. But they get different answers. Why? 3. Variants 2 and 3 look very similar, but 2 gets the wrong answer and 3 gets the right answer. Why? 4. Variant 4 gets the wrong answer. What is computed when variant 4 is run?
Last edited by rabbott at
12:01 Jan 25, 2019.
|