Can someone give me an explanation as to how the following function works recursively. I can understand simpler recursive examples, but I don't understand how (smooth n (- k 1))
gives the value desired under the or statement here.
(define (divides a b)
(= (modulo b a) 0))
(define (smooth n k)
(and (>= k 2)
(or (divides k n)
(smooth n (- k 1)))))
(define (isprime p)
(if (< p 2)
#f
(not (smooth p (floor (sqrt p))))))
I wrote an isprime
function that doesn't use 1
as a prime number, but I still don't quite understand how the above function works/how it works with this example.