问题
Display first N natural numbers, the divisors of which are only 2, 3 and 7. I wrote something like that. I am a beginner in Lisp. Thank you!
defvar x 1
(defun numbers(n)
if(mod x 2 )
(loop for x from 1 to n
do(print x)
)
)
print(numbers())
回答1:
Because I just had some time, you could have a look at this. Might not be the perfect solution but should be a good starting point for a beginner. Check out the books in the info tab to get into the syntax etc.
(defun divisible-by (n m)
"Returns T if N is evenly divisible by M."
(zerop (mod n m)))
(defun numbers (n)
"Print all number upto N which are divisible by 2, 3 and 7."
(loop
for i from 1 upto N
if (and (divisible-by i 2) (divisible-by i 3) (divisible-by i 7))
do (format t "~D~%" i)))
来源:https://stackoverflow.com/questions/58246348/how-to-display-first-n-natural-numbers-knowing-the-divisors-in-lisp