#lang racket (require csc151) (require rackunit) (require rackunit/text-ui) ;;; File: ;;; 000000.rkt ;;; Authors: ;;; The student currently referred to as 000000 ;;; Titus Klinge ;;; Samuel A. Rebelsky ;;; Contents: ;;; Code and solutions for Exam 2 2017F ;;; Citations: ;;; ;; +---------+-------------------------------------------------------- ;; | Grading | ;; +---------+ ;; This section is for the grader's use. ;; Problem 1: ;; Problem 2: ;; Problem 3: ;; Problem 4: ;; Problem 5: ;; Problem 6: ;; ---- ;; Total: ;; Scaled: ;; Errors: ;; Times: ;; : ;; : ;; : ;; ---- ;; Total: ;; +----------+------------------------------------------------------- ;; | Prologue | ;; +----------+ ; Time Log: ; Date Start Finish Elapsed Activity ; Time Spent: ;; +-----------+------------------------------------------------------ ;; | Problem 1 | ;; +-----------+ ; Time Log: ; Date Start Finish Elapsed Activity ; Time Spent: ; Citations: ; Solution: ;;; Procedure: ;;; values-between ;;; Parameters: ;;; start, ;;; finish, ;;; Purpose: ;;; ;;; Produces: ;;; ;;; Preconditions: ;;; ;;; Postconditions: ;;; ; Examples/Tests: ;; +-----------+------------------------------------------------------ ;; | Problem 2 | ;; +-----------+ ; Time Log: ; Date Start Finish Elapsed Activity ; Time Spent: ; Citations: ; Solution: ; Examples/Tests: ;; +-----------+------------------------------------------------------ ;; | Problem 3 | ;; +-----------+ ; Time Log: ; Date Start Finish Elapsed Activity ; Time Spent: ; Citations: ; Solution: ; Examples/Tests: ;; +-----------+------------------------------------------------------ ;; | Problem 4 | ;; +-----------+ ; Time Log: ; Date Start Finish Elapsed Activity ; Time Spent: ; Citations: ; Solution: ; Examples/Tests: ;; +-----------+------------------------------------------------------ ;; | Problem 5 | ;; +-----------+ ; Time Log: ; Date Start Finish Elapsed Activity ; Time Spent: ; Citations: ; Solution: ;;; Procedure: ;;; ;;; Parameters: ;;; ;;; Purpose: ;;; ;;; Produces: ;;; ;;; Preconditions: ;;; ;;; Postconditions: ;;; (define s (lambda (l) (let ([a (iota (length l))]) (let ([a (map even? a)]) (let ([a cadr] [b (map list l a)]) (let* ( [c (filter a b)]) (list (map car c) (map car (filter (negate cadr) b))))))))) ; Examples/Tests: ;; +-----------+------------------------------------------------------ ;; | Problem 6 | ;; +-----------+ ; Time Log: ; Date Start Finish Elapsed Activity ; Time Spent: ; Citations: ; Supplied code ; Solution: ;;; Procedure: ;;; categorize-word ;;; Parameters: ;;; word, a string ;;; Purpose: ;;; Assign one of a few categories to word. ;;; Produces: ;;; category, a string ;;; Preconditions: ;;; [No additional] ;;; Postconditions: ;;; category reasonably describes some characteristic of word. (define categorize-word (lambda (word) (let* ([wordlen (string-length word)] [halflen (quotient wordlen 2)]) (if (even? wordlen) (cond [(zero? wordlen) "empty"] [(string=? (substring word 0 halflen) (substring word halflen)) "repeated"] [else "even length"]) (if (> wordlen 10) "oddly long" (if (= wordlen 1) "one letter" "odd length")))))) ; Examples/Tests: