;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname assig-08) (read-case-sensitive #t) (teachpacks ())) ;; ********************************* assig-08 ********************************** (define-struct silly-string (first middle last)) ;; a SillyStr is either: ;; * a Str of length 0 or 1, or ;; * a (make-silly-string Str SillyStr Str) ;; Requires: first and last have length exactly 1. ;; unsilly is provided as an option for some tests. ;; (unsilly ss) Make ss no longer silly. ;; unsilly: SillyStr -> Str ;; Examples: (check-expect (unsilly "") "") (check-expect (unsilly (make-silly-string "" "a" "")) "a") (check-expect (unsilly (make-silly-string "c" (make-silly-string "" "a" "") "r")) "car") (define (unsilly ss) (cond [(string? ss) ss] [else (string-append (silly-string-first ss) (unsilly (silly-string-middle ss)) (silly-string-last ss))])) ;;Tests: (check-expect (unsilly (make-silly-string "n" (make-silly-string "o" (make-silly-string "n" (make-silly-string "s" "" "e") "n") "s") "e")) "nonsense") ;(check-expect (sillify "a") "a") ;(check-expect (sillify "yo") (make-silly-string "y" "" "o")) ;(check-expect ; (sillify "Babbage") ; (make-silly-string "B" ; (make-silly-string "a" ; (make-silly-string "b" ; "b" ; "a") ; "g") ; "e")) ;(define (sillify s) ; ...) ;; Tests: ;(check-expect ; (unsilly (sillify ; "Those who can imagine anything, can create the impossible.")) ; "Those who can imagine anything, can create the impossible.") ;(check-expect (palindrome? (make-silly-string "h" ; (make-silly-string "e" "l" "l") ; "o")) ; #false) ;(check-expect (palindrome? (make-silly-string "r" ; (make-silly-string "a" "d" "a") ; "r")) ; #true) ;(check-expect (palindrome? (sillify "racecar")) #true) ;(check-expect (palindrome? (sillify "heptapod")) #false) ;(check-expect (palindrome? (sillify "able was I ere I saw elba")) #true) ;(check-expect (palindrome? (sillify "Hannah")) #false) ;(check-expect (palindrome? (sillify "hannah")) #true) ;(define (palindrome? ss) ; ...) (define-struct ingredient (name count)) ;; An Ingredient is a (make-ingredient Str Num) ;; Requires: count > 0. ;; A FoodList is a (listof Ingredient) ;; Requires: no name appears more than once. (define pantry (list (make-ingredient "egg" 12) (make-ingredient "flour" 10) (make-ingredient "butter" 0.5) (make-ingredient "sugar" 2) (make-ingredient "rice" 5) (make-ingredient "cinnamon" 0.005) (make-ingredient "yeast" 0.113) (make-ingredient "raisins" 0.4))) (define cookies (list (make-ingredient "flour" 0.3) (make-ingredient "sugar" 0.06) (make-ingredient "butter" 0.24))) (define raisin-bread (list (make-ingredient "flour" 1) (make-ingredient "sugar" 0.1) (make-ingredient "yeast" 0.007) (make-ingredient "cinnamon" 0.05) (make-ingredient "raisins" 1))) ;(check-expect (quantity "raisins" pantry) 0.4) ;(check-expect (quantity "vinegar" pantry) 0) ;(define (quantity name foods) ; ...) ;(check-expect (find-missing pantry raisin-bread) ; (list (make-ingredient "cinnamon" 0.045) ; (make-ingredient "raisins" 0.6))) ;(check-expect (find-missing pantry cookies) '()) ;(define (find-missing available recipe) ; ...) (define-struct ls (first rest)) ;; a Ls is either ;; '(), or ;; (make-ls first rest) where first is an Int and rest is a Ls. ;(check-expect (ls-length (make-ls 5 (make-ls 7 (make-ls 11 '())))) 3) ;(define (ls-length L) ; ...) ;(check-expect (ls-max (make-ls 5 (make-ls 11 (make-ls 7 '())))) 11) ;(define (ls-max L) ; ...)