6.10

Assignment 14a

home work!

Programming Language ISL

Due Date: Monday at 9:00pm (Week 14)

Purpose To practice designing generative and/or accumulator-based functions.

Remember to explicitly write down your generative ideas, termination conditions, and/or accumulator statements as appropriate.

Graded Exercises

Exercise 1 Design the function transpose, that takes a list of lists of values, and transposes it: when viewed as a table, the rows become columns and vice versa. For example,

(transpose (list (list 1 2 3)
                 (list 4 5 6)
                 (list 7 8 9))) ==>
  (list (list 1 4 7)
        (list 2 5 8)
        (list 3 6 9))

Exercise 2 A Latin square is an n by n grid of n numbers (0 through n - 1), such that each value appears exactly once in each row and column. Design a function is-latin? to check whether a given n by n list-of-lists is indeed a Latin square.

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 ormap andmap.

Exercise 3 Challenge! (Not graded) Design a function create-latin-square. It takes in a [List-of [List-of [Maybe Number]]], and produces a [Maybe [List-of [List-of Number]]]. The input is a partially filled-in grid of numbers: each of these numbers must be present at that position in the final output. The ouput is either a valid Latin square, or #false if no Latin square is possible with the given inputs. For example, the following input is impossible to solve:
(list (list 0      #false #false)
      (list #false 1      #false)
      (list #false 2      #false))
because the first empty position in the first row cannot be any of 0, 1 or 2.