Hello I was wondering if someone could help me with a family tree function in scheme. What I have right now is:

;;proper-blue-eyed-ancestor?: ftn -> boolean
;;consumes:an ftn
;;produces:a list of all the eye colors of the people you can get to 
;;from that node
(define (proper-blue-eyed-ancestor? a-ftn)
  (cond
    [(empty? a-ftn) false]
    [(ftn? a-ftn) (or(proper-blue-eyed-ancestor? 
                        (ftn-father a-ftn))
                    (proper-blue-eyed-ancestor? (ftn-mother a-ftn))
                    (symbol=? 'blue (ftn-eyes a-ftn)))]))

now my problem is the "or" after

(ftn? a-ftn)

causes it to look at the persons u start off with and counts him/her too. For example if the persons name you type in has blue eyes, but his ancestors don't it comes back true, but its supposed to come back false because I only want it to look at the ancestors of that person...any help? oh and putting a "and" in there doesn't work either.

Recommended Answers

All 2 Replies

Try testing the parents of the current person, then recurse if neither parent has blue eyes.

You need a helper function to get it started. Put your current code in the helper function, and then have the main function call the helper function on each parent WITHOUT testing the starting person.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.