Easy: ------ Write a procedure called has-duplicates? which takes a sentence and returns true if and only if the sentence contains a repeated word > (has-duplicates? '(here there and everywhere)) #f > (has-duplicates? '(she loves you yeah yeah yeah)) #t Answer: -------- (define (has-duplicates? sent) (cond ((empty? sent) #f) ((member? (first sent) (bf sent)) #t) (else (has-duplicates? (bf sent))))) Hard: ------ Create a function called at-least? whichs takes a number, a function, and a list and returns #t if at least that number of elements in the list make the function true and $f otherwise > (at-least? 4 even? '(1 2 2 2 3 5 7 9 11 12 13 14)) #t > (at-least? 2 odd? '(1 2 4 6)) #f > (at-least? 0 odd? '(2 4 6 8 10)) #t Answer: -------- Recursively: (define (at-least? n pred? sent) (cond ((empty? s) (= n 0)) ((pred? (first sent)) (at-least? (-n 1) pred? (bf s))) (else (at-least? n pred? (bf s))))) HOFS: (define (at-least? n pred? sent) (>= (count (keep? pred? sent)) n)) Write deeper-count which take a predicate and a sentence and counts only the letters in each word that make the predicate return true. NO RECURSION > (deeper-count number? '(a g00d 5p3ll3r)) 5 > (deeper-count even? '(337 42 963)) 3 Answer: -------- (define (deeper-count pred? s) (count (keep pred? (every (lambda (w) (every (lambda (l) l) w)) s)))) OR (define (deeper-count pred? s) (count (keep pred? (accumulate word s)))) Harder: -------- Write a procedure make-non-functional that takes a function of two arguments f and returns a procedure that acts like f half the time and returns a false value the other half of the time *HINT* (rand 2) returns a value 0 or 1. > (define (minus x y) (- x y)) plus > (define mnf-minus (make-non-funtional minus)) mplus > (mnf-minus 2 1) #f > (mnf-minus 2 1) 1 Answer: -------- (define (make-non-functional f) (lambda (x y) (if (equal? (rand 2) 1) (f x y) #f)))