Blame


1 12687dd9 2023-08-04 jrmu ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 12687dd9 2023-08-04 jrmu ;; about the language level of this file in a form that our tools can easily process.
3 12687dd9 2023-08-04 jrmu #reader(lib "htdp-intermediate-reader.ss" "lang")((modname 18.1.13) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
4 12687dd9 2023-08-04 jrmu (define-struct child (father mother name date eyes))
5 12687dd9 2023-08-04 jrmu
6 12687dd9 2023-08-04 jrmu #|
7 12687dd9 2023-08-04 jrmu A child is a structure
8 12687dd9 2023-08-04 jrmu (make-child fa mo na da ec)
9 12687dd9 2023-08-04 jrmu where fa, mo are family-tree-nodes, name and eyes are symbol, and date is a number.
10 12687dd9 2023-08-04 jrmu
11 12687dd9 2023-08-04 jrmu A family tree node (ftn) is either
12 12687dd9 2023-08-04 jrmu 1. empty or
13 12687dd9 2023-08-04 jrmu 2. (make-node fa mo na da ec)
14 12687dd9 2023-08-04 jrmu where fa, mo are family-tree-nodes and na, ec are symbols, and da is a number.
15 12687dd9 2023-08-04 jrmu
16 12687dd9 2023-08-04 jrmu A direction is either
17 12687dd9 2023-08-04 jrmu 1. the symbol 'father or
18 12687dd9 2023-08-04 jrmu 2. the symbol 'mother.
19 12687dd9 2023-08-04 jrmu
20 12687dd9 2023-08-04 jrmu A path is either
21 12687dd9 2023-08-04 jrmu 1. empty or
22 12687dd9 2023-08-04 jrmu 2. (cons d p)
23 12687dd9 2023-08-04 jrmu where d is a direction and p is a path.
24 12687dd9 2023-08-04 jrmu
25 12687dd9 2023-08-04 jrmu to-blue-eyed-ancestor : ftn -> path or false
26 12687dd9 2023-08-04 jrmu Return the path to a blue-eyed-ancestor, by searching out the paternal family tree first. (Given two or more blue-eyed-ancestors, the path returned will be the one that follows the paternal path in any given fork). Non-proper ancestors are returned as empty paths (a-ftn itself is counted as an ancestor).
27 12687dd9 2023-08-04 jrmu
28 12687dd9 2023-08-04 jrmu |#
29 12687dd9 2023-08-04 jrmu
30 12687dd9 2023-08-04 jrmu (define (to-blue-eyed-ancestor a-ftn)
31 12687dd9 2023-08-04 jrmu (cond
32 12687dd9 2023-08-04 jrmu [(empty? a-ftn) false]
33 12687dd9 2023-08-04 jrmu [(symbol=? 'blue (child-eyes a-ftn)) empty]
34 12687dd9 2023-08-04 jrmu [else (local ((define f (to-blue-eyed-ancestor (child-father a-ftn)))
35 12687dd9 2023-08-04 jrmu (define m (to-blue-eyed-ancestor (child-mother a-ftn))))
36 12687dd9 2023-08-04 jrmu (cond
37 12687dd9 2023-08-04 jrmu [(or
38 12687dd9 2023-08-04 jrmu (cons? f)
39 12687dd9 2023-08-04 jrmu (empty? f)) (cons 'father f)]
40 12687dd9 2023-08-04 jrmu [(or
41 12687dd9 2023-08-04 jrmu (cons? m)
42 12687dd9 2023-08-04 jrmu (empty? m)) (cons 'mother m)]
43 12687dd9 2023-08-04 jrmu [else false]))]))
44 12687dd9 2023-08-04 jrmu
45 12687dd9 2023-08-04 jrmu (define Carl (make-child empty empty 'Carl 1926 'green))
46 12687dd9 2023-08-04 jrmu (define Bettina (make-child empty empty 'Bettina 1926 'green))
47 12687dd9 2023-08-04 jrmu (define Adam (make-child Carl Bettina 'Adam 1950 'yellow))
48 12687dd9 2023-08-04 jrmu (define Dave (make-child Carl Bettina 'Dave 1955 'black))
49 12687dd9 2023-08-04 jrmu (define Eva (make-child Carl Bettina 'Eva 1965 'blue))
50 12687dd9 2023-08-04 jrmu (define Fred (make-child empty empty 'Fred 1966 'pink))
51 12687dd9 2023-08-04 jrmu (define Gustav (make-child Fred Eva 'Gustav 1988 'brown))
52 12687dd9 2023-08-04 jrmu