yield_hw-2


View on GitHub | Download Local

Click to view slide text

CS3323 Homework 7 – Python yield We call an integer SuPrP2 if it can be written as a sum of a prime and a power of 2. For example, 15 is a SuPrP2 since 15 = 13 + 21 , but 16 is not.

  1. Write a Python generator that yields all power of two starting from 1 = 20 .
  2. Write a Python generator that on an input positive integer n, yields all SuPrP2 numbers in the increasing order that are greater than n.
  3. Let N be your student ID number. Use the generator to find 20 consecutive SuPrP2 numbers right after N . Note:
  4. You may use, with clear citations, functions which we developed in class, but you should not import any modules.
  5. You need to pay attention to efficiency of the program as numbers involved are quite large.
  6. Please include the answer to the question (3) as comments in the source code, and submit the source code as text file.

1