Source of Nothingness - -5356")

* Menu

[[About:self:AboutPage.txt]] | [[Profile:http://iddy.jp/profile/southly/]] | [[まとめ:self:1163859357.txt]] | [[オリジナル:http://ninjinix.x0.com/rn/]] | [[xyzzy:http://raido.sakura.ne.jp/southly/xyzzy/site-lisp/]] | [[あんてな:http://i-know.jp/southly/listall]] | [[■:http://raido.sakura.ne.jp/southly/lisp/ni/view.lisp]] | [[buzz:http://www.google.com/profiles/southly#buzz]]

* 素数を求める

素直に再帰
(defun generate-primes (limit)
  (labels ((check (x prime)
             (cond ((endp prime)
                    t)
                   ((zerop (rem x (car prime)))
                    nil)
                   (t
                    (check x (cdr prime)))))
           (main (n x prime)
             (cond ((> x n)
                    (nreverse prime))
                   ((check x prime)
                    (main n (+ x 2) (cons x prime)))
                   (t
                    (main n (+ x 2) prime)))))
    (format t "~{ ~D~}~%" (main limit 3 (list 2)))))

* 素数を求める

素直にループ
(defun generate-primes (limit)
  (let ((prime nil))
    (push 2 prime)
    (do ((x 3 (+ x 2)))
        ((> x limit))
      (if (dolist (i prime t) (if (zerop (rem x i)) (return nil)))
          (push x prime)))
    (format t "~{ ~A~}~%" (nreverse prime))))

* 2006-06-22