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

Need help figuring this out using scheme: please use map/apply/filter Map/Apply/

ID: 3717580 • Letter: N

Question

Need help figuring this out using scheme:

please use map/apply/filter

Map/Apply/Filter 7. Perfect Squares (10 Points) Using a combination of map, apply and/or filter write a function named perfect-squares that takes exactly one argument, a list of numbers. This function should return only the numbers that are perfect squares, which we will define as having square roots which are whole numbers. You may not use recursion to solve this problem, and must use some combination of the three functions mentioned above, although not all need to be used Hint: To test if something is a whole number, use the built in Scheme function integer? Example output is shown below > (perfect-squares (123456789)) (1 4 9 > (perfect-squares '(15 16 17 24 25 26 25)) 16 25 25) > (perfect-squares '(2 3 5 6))

Explanation / Answer

Answer :

(define perfect-square-helper
(lambda (x y)
(if (null? x)
(reverse y)
(if (integer? (sqrt (car x)))
(perfect-square-helper (cdr x) (cons (car x) y))
(perfect-square-helper (cdr x) y)))))

(define perfect-square
(lambda (x)
(perfect-square-helper x '())))


(define x '(1 2 9 16 5 64))

(perfect-square x)

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