UNB/ CS/ David Bremner/ teaching/ cs2613/ assignments/ CS2613 Assignment 1


What to hand in, and how to hand it in



For questions 1 to 3, you should use only the functions included in #lang racket

Q1: drop-divisible

Write a function drop-divisible that takes a number and a list of numbers, and returns a new list containing only those numbers not "non-trivially divisible" by the the number. You can use the following test to deduce what the function should do.

(module+ test
    (check-equal? (drop-divisible 3 (list 2 3 4 5 6 7 8 9 10)) (list 2 3 4 5 7 8 10)))

Your implimentation should use

Q2: sieve-with

Using drop-divisible and direct recursion (i.e. no higher order functions like filter or map), write a function that takes a list of divisors, a list of numbers to test, and applies drop-divisible for each element of the list of divisors. Here is a test your code should pass

(module+ test
    (check-equal? (sieve-with '(2 3) (list 2 3 4 5 6 7 8 9 10)) (list 2 3 5 7)))

Q3: sieve

Impliment a function sieve that uses sieve-with to find all prime numbers and most n. This should be a relatively simple wrapper function that just sets up the right arguments to sieve-with. Note that not all potential divisors need to be checked, you can speed up your code a lot by stopping early. Here is a test case your code should pass:

(module+ test
  (check-equal? (sieve 10) (list 2 3 5 7)))

Q4 test against a second implimentation

Write another test for your code that