20-CS-4003-001 |
Organization of Programming Languages |
Fall 2018 |
---|---|---|

Streams |

All lectures
**Hamming's Sequence**

Compare threaded streams and non-blocking streams

- | Uses threaded monitors | |

- | Uses non-blocking streams |

**Problem:**

**Given:** Set ` P` of distinct primes.

**Example:** For *P* = {3,5,11}

**Solution:**` 3,5,9,11,15,25,27,33,45,55,75,81,99,121,125,135 ...`

**Possible Program**

For all numbers 1,2,3 ... do the following: If the number has only prime factors inP, print it.

This is unfortunately too slow to be of value.

**Better Program**

_ 5, 11, 25, 55, 121, 125, ... / / 3 < \ \_ 9, 15, 27, 33, 45, 75, 81, 99, 135, ... 3 * {3, 5, 9, 11, 15, 25, 27, 33, 45, ...}So, generalizing:

Hamming(P) = ifPis empty then return nothing. return First(P) + Merge(First(P)*Hamming(P), Hamming(Rest(P))).