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 121Explanation / 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
)))
)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.