Scheme Write a procedure in Scheme called multiples that takes two parameters: b
ID: 3673736 • Letter: S
Question
Scheme
Write a procedure in Scheme called multiples that takes two parameters: base (assume it is positive) and N. Return a list of all positive whole-number multiples of base less than or equal to N.
One approach is to think of this as an application of map. This is not the only approach.
scheme@(guile-user)> (multiples 2 9)
$8 = (2 4 6 8)
This code was provided in a previous post but returns an #<unspecified> error when running: (multiples 2 9)
(define (multiples n f)
(if (= 0 (remainder n f))
f
(if (< f n)
(multiples n (+ f 1))
)))
Explanation / Answer
Hi, You can take help from here:
(define (multiples n f)
(multiplesUtil n f 1)
)
(define (multiplesUtil n f counter)
(if (< (* counter f) n ))
(* counter f)
(if (< f n)
(multiplesUtil n f (+ counter 1))
)))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.