A family-tree
is either:
'unknown
(make-ft name eye-color mom dad)
where name
and eye-color
are symbols,
and mom
and dad
are family-tree
s.
(define-struct ft (name eye-color mom dad))
;; path-to-blue-eyes : family-tree list-of-symbols or #f ;; finds the path to a blue eyed ancestor (define (path-to-blue-eyes ft) (cond [(eq? ft 'unknown) #f] [else (if (eq? (ft-eye-color ft) 'blue) '() (let ([mom-path (path-to-blue-eyes (ft-mom ft))] [dad-path (path-to-blue-eyes (ft-dad ft))]) (cond [(and mom-path dad-path) (cons 'mom mom-path)] [(and mom-path (not dad-path)) (cons 'mom mom-path)] [(and dad-path (not mom-path)) (cons 'dad dad-path)] [else #f])))])) (define tutu (make-ft 'emily 'brown 'unknown 'unknown)) (define opa (make-ft 'bruce 'blue 'unknown 'unknown)) (define mom (make-ft 'alice 'green tutu opa)) (define dad (make-ft 'bill 'brown 'unknown 'unknown)) (define me (make-ft 'robby 'hazel mom dad))
Hand evaluate:
(path-to-blue-eyes me)
Solution