Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use the map and reduce functions defined as (define map (lambda (f l) (if (null?

ID: 3813101 • Letter: U

Question

Use the map and reduce functions defined as (define map (lambda (f l) (if (null? l), () (cons (f Car l)) (map f (cdr 1)))))) (define reduce (lambda (op 1 id) (if (null? l) id (op car l (reduce op (cdr l) id))))) to implement functions minSquareVal and maxSquareVal that determine the minimal square value and maximal square value respectively, of a list of integer numbers. Example (define minSquareVal (lambda (l) ...)) ... (min Square Val '(-5 3 -7 10 -11 8 7)) rightarrow 9 (define maxSquareVal (lambda (l) ...)) ... (maxSquareVal '(-5 3 -7 10 -11 8 7)) rightarrow 121

Explanation / Answer

Solution:

(define minSquareVal (lambda (l)
(let ((sqrl (map (lambda (a) (* a a)) l)))
(reduce
(lambda (a b)
(if (< a b) a b)
) sqrl 0
)))
)


(define maxSquareVal (lambda (l)
(let ((sqrl (map (lambda (a) (* a a)) l)))
(reduce
(lambda (a b)
(if (> a b) a b)
) sqrl 0
)))
)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote