Assignment 4 - Spring 2021

Permutations

Assigned: Wed, Apr 21
Due: Wed, May 5

For this assignment you will:


Assignment Setup

  1. Open a browser and copy/paste this URL: https://classroom.github.com/a/MOTfacIb

  2. Login to Github and you will be prompted to accept this assignment
    1. After you click on the [Accept this assignment] button, you will see a new page display in your browser with the message:
      1. You accepted the assignment, Assignment 4. We're configuring your repository now. This may take a few minutes to complete. Refresh this page to see updates.
    2. After you refresh the page you should see a page with the message: “You're ready to go!”
    3. Note: this will create your own copy of Assignment 4 for you to work on, but it's not on your computer yet.

  3. Click on the URL where your assignment repository has been created: https://github.com/Vassar-cs101-mlsmith/assignment-4-yourGitHubID
    1. you are now on the GitHub page for your Assignment 4 repository

  4. Click on the green button to download your [Code]
    1. a “Clone” dialog box will appear, with the HTTPS tab underlined in red (if not, click on the HTTPS tab to select it)
    2. select the last option labeled “Download ZIP” and save it on your computer
    3. move the Assignment 4 zip file from its download location to your cs101 course folder.
    4. extract the contents of the zip file either by double-clicking on it or control-clicking on it and selecting the appropriate option to extract its contents
    5. navigate into your assign4 folder and confirm you see the assign4.rkt file there.

Background

The permutations of a list of numbers is the list of all possible sequences of those numbers. We will represent the permutations of a list of numbers as a list of lists of numbers. When your program is completed and correct, it will demonstrate the following behavior in the Interactions Pane of DrRacket:

Welcome to DrRacket, version 8.0 [cs].
Language: Intermediate Student; memory limit: 512 MB.
All 12 tests passed!
> (permutations '())
(list '())
> (permutations '(1))
(list (list 1))
> (permutations '(1 2))
(list (list 1 2) (list 2 1))
> (permutations '(1 2 3))
(list (list 1 2 3) (list 2 1 3) (list 2 3 1) (list 1 3 2) (list 3 1 2) (list 3 2 1))
> 


Let's take a moment to describe the above sample behavior:


Things get more interesting for larger lists:


Write the program

Note: this assignment is similar to the exercises described in HtDP/2e Section 12.4 of HtDP/2e. The main difference is this assignment deals with permuting a list of numbers, while the HtDP/2e version involves permuting a word (a list of one-character strings). It may help to reread this section of the text, with these differences in mind.

Here's some advice given in HtDP/2e for this assignment: The solution of this exercise is a series of functions. Patiently stick to the design recipe and systematically work through your wish list.

And here's my extended version of that advice, with a head start and some hints to help guide you:

Submitting your work