2

显示前N个自然数,除数只有 2、3 和 7。我写了类似的东西。我是 Lisp 的初学者。谢谢!

defvar x 1
(defun numbers(n)
    if(mod x 2 )
    (loop for x from 1 to n
    do(print x)
    )
)
print(numbers())
4

1 回答 1

3

因为我刚好有时间,你可以看看这个。可能不是完美的解决方案,但对于初学者来说应该是一个很好的起点。查看信息选项卡中的书籍以了解语法等。

(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)))
于 2019-10-05T13:26:30.427 回答