43S-CS107-Final-Solution

43S-CS107-Final-Solution - CS107 Spring 2007 Handou t 43S...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Problem 2: Scheme (15 points) a) (4 points) A derangement is a permutation of the integers 1 through n such that no number k falls in the k th position. So, (4 1 3 5 2) is certainly a permutation, but it’s not a derangement, because the 3 sits in the 3 rd position. (3 5 1 2 6 4) is a derangement of length 6, and (2 3 7 6 1 5 4) is a derangement of length 7. (1 2 3 4 5 6 7 8) is as far as a permutation can be from a derangement. Write a function called derangement? that returns #t if and only if the supplied list of numbers, assumed to be a real permutation of all the integers 1 through the list length, is also a derangement. Use car - cdr recursion. Feel free to write helper functions. ;;; ;; Returns true if and only if the specified permutation (which
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/14/2010 for the course CS 107 taught by Professor Cain,g during the Spring '08 term at Stanford.

Page1 / 9

43S-CS107-Final-Solution - CS107 Spring 2007 Handou t 43S...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online