;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname 04consp) (read-case-sensitive #t) (teachpacks ((lib "universe.rkt" "teachpack" "2htdp") (lib "image.rkt" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "universe.rkt" "teachpack" "2htdp") (lib "image.rkt" "teachpack" "2htdp"))))) ; DEMO: How deep is a conspiracy? (October 2) #| **Data description**\ A _person is a structure: (make-person first last) where `first` and `last` are strings A _conspiracy_ is either - A structure: (make-cell head recruits1 recruits2) where - `head` is a person - `recruits1` is a conspiracy - `recruits2` is a conspiracy - A structure (make-no-recruits) |# (define-struct person (first last)) (define-struct cell (head recruits1 recruits2)) (define-struct no-recruits ()) (define NR (make-person "Norman" "Ramsey")) (define AB (make-person "Ali" "Boreiko")) ;; depth : conspiracy -> number ;; return the max number of relays to reach any leaf in the conspiracy (define (depth c) (cond [(no-recruits? c) 0] [(cell? c) (add1 (larger (depth (cell-recruits1 c)) (depth (cell-recruits2 c))))])) ; larger : number number -> number ; reutrn the larger of the two numbers (define (larger n m) (max n m)) (check-expect (depth (make-no-recruits)) 0) (check-expect (depth (make-cell NR (make-no-recruits) (make-no-recruits))) 1) (check-expect (depth (make-cell NR (make-cell AB (make-no-recruits) (make-no-recruits)) (make-no-recruits))) 2)