Assigned: Wed, Apr 21
Due: Wed, May 5
For this assignment you will:
cs101
course folder.assign4
folder and confirm you see the assign4.rkt
file there. 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:
append
the above two lists together into one list 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:
assign4.rkt
, in which I've given you the first function, permutations
, fully implemented and complete in terms of the Design Recipe. permutations
function calls a helper function, insert-everywhere/in-all-lons
, which you must design and implement using the Design Recipe. This helper function is on your wish list, and it is your starting point for working on this assignment. insert-everywhere/in-all-lons
function will require a helper function: insert-everywhere/in-one-lon
. Put this function on your wish list to design next. insert-everywhere/in-one-lon
function will require one final helper function, which I called: insert-beginning/of-all-lons
. Put this function on your wish list to design next.insert-beginning/of-all-lons
without any further need for helper functions. Once you finish this function, your wish list will be empty! assign4.rkt
file onto your browser where it says, “Drag files here to add them to your repository”assign4.rkt
file file should now be in your Assignment 4 GitHub repository.