COS 371: Programming Languages

Spring 2022

hw5: Sieve of Eratosthenes

Due: Friday, 02/25 at 22:00

This assignment is to be done individually. You can share ideas and thoughts with other people in the class, but you should code your own assignment.

1. Goals

To build an infinite list of primes using an ancient algorithm.

2. Introduction

Recall that a prime number is a positive integer greater than 1 that has no positive divisors other than 1 and itself. A wide variety of techniques have been devised to compute prime numbers. One of the oldest techniques is the Sieve of Eratosthenes, which is remarkably simple:
Start with the infinite list 2, 3, 4, 5, .... The head of this list (2) is a prime. If you filter out all values that are a multiple of 2, you get the list 3, 5, 7, 9, .... The head of this list (3) is a prime. Moreover, if you filter out all values that are a multiple of 3, you get the list 5, 7, 11, 13, 17, .... Repeating the process, you repeatedly take the head of the resulting list as the next prime, and then filter from this list all multiples of the head value.
This is the Sieve of Eratosthenes, one of the earliest known algorithms, dating back to about 200 BC, and is named after the eponymous Greek mathematician who lived around then. See this article for an animation of the process.

3. Specification

4. Notes

5. Optional Challenges

6. Submission

Submit your code in a file called sieve.scm.

Start early, have fun, and discuss questions on Moodle.