Sample Solution and Test File

Program 1: Common Lisp

Due Date

This assignment is due at the beginning of the lecture on Wednesday, September 22nd.

Partners

Everyone should complete this assignment individually.

Purpose

The purpose of this assignment is to give you practice solving problems in Common Lisp.

Problem A: Permutations

Write a function called permutation that has a single parameter called number. Assume that the parameter will take on an integer value between 0 and 10 inclusive. (No error checking is needed.) The function should print out all of the permutations in descending lexigraphical order.

Sample Input

(permutation 3)

Required Output

The permutations are:

3 2 1
3 1 2
2 3 1
2 1 3
1 3 2
1 2 3

Problem B: Selection Sort

Write a function called selection-sort that has a single parameter called alist. Assume that the parameter will contain a list of some unknown number of integers. Furthermore, you may assume that all of the integers are unique. (No error checking is needed.) The function should sort the list into ascending order using selection sort and then print out the final list.

Sample Input

(selection-sort '(1 5 3 4 2))

Required Output

The original list was: '(1 5 3 4 2)
The sorted list is: '(1 2 3 4 5)

What to Submit

  1. A printout of the source code that you produce.
  2. A printout of your program running on the sample output above.
  3. An e-mail of your solution to John at paxton@cs.montana.edu on or before Wednesday, September 22nd at noon.

Grading

Valid XHTML 1.0!