6.6

Assignment 18

home work!

Programming Language ISL

Due Date THursday 4/11 at 9pm

Purpose To practice generative recursion.

Expectations
  • You should submit a single .rkt file containing your responses to all exercises via the Handin Server. We accept NO email submissions. Failure to submit a .rkt file will result in a 0.

  • You are only allowed to use the language specified at the top of this page: failure to do so will result in a 0.

  • Your code MUST conform to the guidelines outlined in the style guide on the course website. The style guide will be updated as the semester progresses so please remember to read it before submitting each assignment.

  • You must follow all the steps of the design recipe when completing this assignment.

  • Please be sure to look at the feedback for assignment 12 before submitting, as we will be grading you more harshly on things we have warned you about before.

  • You must submit this assignment with your partner. Please make sure you can submit with your partner before 5pm on Thursday or we cannot guarantee that you will be able to submit your homework before the deadline. If the course staff are unable to assist you after 5pm and this causes your homework to be late we will not grant an extension.

Exercise 1 Design the function string-split, which given a string to split and a non-empty delimiter splits the string by that delimiter. For example, (string-split "hello%%bob%%%i%%%%am%%jack" "%%") should return (list "hello" "bob" "%i" "" "am" "jack").

Exercise 2 Design a function make-paragraph. It takes in a list of strings, each of which is a word with no spaces in it, and a positive integer representing the line width. It splits the list of words into a list of lists of words, representing a single line of text in a paragraph, such that each line of text is no longer than the given line width. For this problem, you can ignore the spaces between words, and you should fit as many words as you can on a line. For example,

(make-paragraph (list "hello" "is" "a" "greeting" "in" "English") 8) ==>
   (list (list "hello" "is" "a")
         (list "greeting")
         (list "in")
         (list "English"))
(make-paragraph (list "hello" "is" "a" "greeting" "in" "English") 9) ==>
   (list (list "hello" "is" "a")
         (list "greeting")
         (list "in" "English"))

There is a behavior left unspecified in the problem description above. Determine what it is, decided how to handle it, and document your choice.

Exercise 3 Recall our definition of a Matrix from the exam:

; A Matrix is a [List-of [List-of Nat]]
; Interpretation: A Matrix, where all inner lists have the same length

A Latin square is a square matrix (one with n rows and n columns) that contains only the numbers (0 through n - 1), such that each value appears exactly once in each row and column. Design a function is-latin? that accepts a Matrix that is a square matrix and returns whether or not it is a Latin square.

For example, the following matrix would be a latin square:

(define LATIN (list (list 0 1 2) (list 1 2 0) (list 2 0 1)))

while this one would not

(define NOT-LATIN (list (list 0 1 2) (list 2 1 0) (list 1 2 0)))

Hint: A useful helper function here might check whether a given list contains all the values 0 through n - 1. You can design this very succinctly using build-list, member? and andmap.