;; represent a family tree, where each person in the tree has a name, ;; year of birth, eye color, mother, and father (define-struct person (name year eye mother father)) ;; a Person is a (make-person String Natural String Treenode Treenode) ;; interp: a person in a family tree where ;; name ;; year ;; eye ;; mother, father are the roots of the person's mother's and father's trees ;; a Treenode is one of ;; false ;; Person ;; interp: Treenode represents a family tree (define MARYTREE (make-person "Mary" 1980 "blue" (make-person "Ann" 1960 "green" false (make-person "Fred" 1936 "blue" false false)) (make-person "Joe" 1960 "blue" false false))) ;;; treenode-fcn: Treenode -> ;;; ;(define (treenode-fcn atn) ; (cond [(boolean? atn) (...)] ; [(person? atn) (... (person-name atn) ; (person-year atn) ; (person-eye atn) ; (treenode-fcn (person-mother atn)) ; (treenode-fcn (person-father atn)))])) ;; count-blue-eyed: Treenode -> Natural ;; consumes a family tree and produces the number of people in the tree with blue eyes (define (count-blue-eyed atn) (cond [(boolean? atn) 0] [(person? atn) (if (string=? (person-eye atn) "blue") (+ 1 (count-blue-eyed (person-mother atn)) (count-blue-eyed (person-father atn))) (+ (count-blue-eyed (person-mother atn)) (count-blue-eyed (person-father atn))))])) (check-expect (count-blue-eyed false) 0) (check-expect (count-blue-eyed MARYTREE) 3)