racket - Finding a prime number in Scheme using natural recursion -
How do I still do my own design program, but are successful in being trapped again. This time this question is 11.4.7:
The function is not developed - luck is not - & lt; = I consumes a natural number [> = 1], i, and a natural number i, i
use-no-divisible by & lt; = I to define the prime minister?, Which uses a natural number and determines whether it is dominant or not
In the first part, I did not have much hard time:
;; A natural number [& gt; = 1] is either 1. 1 or ;; 2. (AD1N) where n is a natural number [& gt; = 1]. ;; Not-divisible by & lt; = I: N [& gt; = 1] N - & gt; Boolean (not defined) is not divided (litti; = iim) (cond [(= 1 1) true] [otherwise (conv ([= (remaining miles) 0) false] [Other (not-not divided and lieutenant ; = I (all 1i) M)])))) (not-divisible by & lt; = i 3 6); Expected: Incorrect (not-divisible by & lt; = i 6 7); Expected: True
But I can not see how I can use a variable when using natural recursion. I thought about using a list, but it presents the same problem.
The only solution I can see is giving another variable - let's assume X-N, and After that, just like this - no-divisible by & lt; = I does this but I think the authors intend to do this in some other, simple way. (And I do not even know what I have described.)
This problem is actually ending my butt, so any help or hint, if you can, So good!
(defined (prime minister? N) (not-divisible by & lt; = I (sub1 n) n))
Comments
Post a Comment