CS 246 Programming Paradigms
Home Work #3
Due on Tuesday, April 2

Implement the following Squeak methods:

  1. Sum of factorials:

    n sumFac. "Returns 0! + 1! + ... + N!"

  2. Define the method:

    n divisors. "Returns [n1,..,nk] a list of all divisors of N (i.e. each ni divides N evenly)"

    Example:

    n divisors. "Returns #(1, 2, 3, 4, 6, 12)"

  3. A prime number N is a number whose only divisors are 1 and N. Using divisors from above, write the method:

    n isPrime. "Returns true if N is prime, false otherwise

    Using isPrime, write Smalltalk code that will compute all the prime numbers between 1 and N,
    where N is any given number.

You will need to use arrays or ordered collections to store your results. See a short overview on the most essential features here.