Question: The question is coded in Dr.Racket Information you need: (@htdd Participant) (define-struct participant (name topics mentees)) ;; Participant is (make-participant String (listof String) (listof Participant))

The question is coded in Dr.Racket

Information you need:

(@htdd Participant) (define-struct participant (name topics mentees)) ;; Participant is (make-participant String (listof String) (listof Participant)) ;; interp. a participant with a name, list of topics they have interest or ;; expertise in, and a list of participants that they mentor

(define LOS0 empty) (define LOS1 (list "interviewing")) (define LOS2 (list "communication skills" "testing" "code reviews")) (define LOP0 empty) (define P0 (make-participant "Xavier Maxwell" (list "testing" "data science") empty)) (define P1 (make-participant "Sarah Jackson" (list "algorithms" "communication skills" "data mining") empty)) (define P2 (make-participant "Ling Xu" (list "writing" "machine learning" "programming") empty)) (define LOP1 (list P1 P2)) (define P3 (make-participant "Ananya Kumar" (list "programming" "writing" "testing" "cybersecurity") LOP1)) (define P4 (make-participant "Ella Mason" (list "data science" "writing" "data mining") (list P3))) (define P5 (make-participant "Ora Jacobson" (list "communication skills" "testing" "interviewing" "code reviews") empty)) (define P6 (make-participant "Sam Hu" (list "programming" "communication skills" "algorithms" "visualization") empty)) (define P7 (make-participant "Mandy Wilson" (list "game development" "programming" "graphical design") empty)) (define P8 (make-participant "James Ploshynsky" (list "machine learning" "AI") (list P5 P6 P7))) (define P9 (make-participant "Ayra Nguyen" (list "programming" "writing" "data science") (list P0 P4 P8)))

#; (define (fn-for-participant p0) (local [(define (fn-for-participant p) (... (participant-name p) (fn-for-lot (participant-topics p)) (fn-for-lop (participant-mentees p)))) (define (fn-for-lop lop) (cond [(empty? lop) (...)] [else (... (fn-for-participant (first lop)) (fn-for-lop (rest lop)))])) (define (fn-for-lot lot) (cond [(empty? lot) (...)] [else (... (first lot) (fn-for-lot (rest lot)))]))] (fn-for-participant p0)))

Question given:

Refactor the following function design wherever possible so that it uses built-in abstract functions. You should use the (listof X) format.

- The function definition MUST call one or more built-in abstract ;; functions.

;; - For maximum credit the function definition should use the most clear ;; and expressive combination of abstract functions. In particular, while ;; it is possible to just use foldr for these problems that is not always ;; correct. If what is happening is a filter, then it is not correct to ;; just implement filtering with foldr.

;; - The function definition MUST NOT be recursive.

;; - The function definition MUST NOT use any part of the recursive Natural ;; template or the (listof X) template. ;; - it must not include (cond [(empty? ... anywhere ;; - it must not include (cond [(zero? ... anywhere ;; - it must not include (if (empty? ... anywhere ;; - it must not include (if (zero? ... anywhere

;; - The result of the function must directly be the result of one of the ;; built-in abstract functions. So, for example, the following is not ;; a valid function body: ;; - You MUST NOT change or comment out any check-expects, but you are free ;; to add new ones.

What we are Given to complete problem:

(@problem 4) (@htdf count) (@signature Participant -> Natural) ;; Produce number of participants reachable by a participant's mentees list

(check-expect (count P0) 1) (check-expect (count P3) 3) (check-expect (count P9) 10)

(@template-origin Participant (listof Participant) encapsulated)

(define (count p) (local [(define (count--participant p) (+ 1 (count--lop (participant-mentees p)))) (define (count--lop lop) (cond [(empty? lop) 0] [else (+ (count--participant (first lop)) (count--lop (rest lop)))]))] (count--participant p)))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!