Source of Nothingness

* Menu

About | Profile | まとめ | オリジナル | xyzzy | あんてな | | 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

* 素数を求める。

とりあえず、アルゴリズム事典から。
よりLispらしく。
(defun generatePrimes (n)
  (let ((k 0)
        (prime (make-vector n :fill-pointer 0)))
    (vector-push 2 prime)
    (incf k)
    (do ((x 3 (+ x 2))
         (i 0 0))
        ((>= k n))
      (while (and (< i k) (/= 0 (rem x (aref prime i))))
        (incf i))
      (when (= i k)
        (vector-push x prime)
        (incf k)))
    prime))

* xyzzy lisp : format ~X

(format nil "~X" #x123abc)
"123abc"
(format nil "~:X" #x123abc)
"123,abc"
(format nil "~@X" #x123abc)
"+123abc"
(format nil "~:@X" #x123abc)
"+123,abc"
(format nil "~10X" #x123abc)
"    123abc"
(format nil "~10,'*X" #x123abc)
"****123abc"
(format nil "~10,'*:@X" #x123abc)
"**+123,abc"
(format nil "~10,'*,'-,2:X" #x123abc)
"**12-3a-bc"

* xyzzy lisp : format ~D


(format nil "~D" 12345)
"12345"
(format nil "~:D" 12345)
"12,345"
(format nil "~@D" 12345)
"+12345"
(format nil "~:@D" 12345)
"+12,345"
(format nil "~10D" 12345)
"     12345"
(format nil "~10,'*D" 12345)
"*****12345"
(format nil "~10,'*:@D" 12345)
"***+12,345"
(format nil "~10,'*,'-,2:D" 12345)
"***1-23-45"

* Scrapbook : template

http://ray.sakura.ne.jp/template/index.html

* xyzzy lisp : format ~O


(format nil "~O" #o12345)
"12345"
(format nil "~:O" #o12345)
"12,345"
(format nil "~@O" #o12345)
"+12345"
(format nil "~:@O" #o12345)
"+12,345"
(format nil "~10O" #o12345)
"     12345"
(format nil "~10,'*O" #o12345)
"*****12345"
(format nil "~10,'*:@O" #o12345)
"***+12,345"
(format nil "~10,'*,'-,2:O" #o12345)
"***1-23-45"

* xyzzy lisp : format ~B


(format nil "~B" #b11010)
"11010"
(format nil "~:B" #b11010)
"11,010"
(format nil "~@B" #b11010)
"+11010"
(format nil "~:@B" #b11010)
"+11,010"
(format nil "~10B" #b11010)
"     11010"
(format nil "~10,'*B" #b11010)
"*****11010"
(format nil "~10,'*:@B" #b11010)
"***+11,010"
(format nil "~10,'*,'-,2:B" #b11010)
"***1-10-10"

* Scrapbook : C/C++向け多倍長整数資料を探している人のためのガイド @ 2005年10月 @ ratio - rational - irrational @ IDM

http://idm.s9.xrea.com/ratio/2005/10/30/000283.html

* Scrapbook : soft/Xming - ペンギンの杜 - Linuxソフトライブラリ -

http://www.ut-info.com/linux-soft/index.php?soft%2FXming

どうしてもXが必要になったときに

*

(defun delete-blank-lines-region (start end)
  (interactive "*r")
  (save-restriction
    (narrow-to-region start end)
    (save-excursion
      (goto-char (point-min))
      (while (and (scan-buffer "^$" :no-dup t :regexp t)
                  (not (eobp)))
        (delete-blank-lines)))))

* Scrapbook : エレベーター事故まとめ

http://topnews.at-ninja.jp/

* xyzzy lisp : formatのCONTROL-STRINGとパラメータと「:」と「@」の関係

~a	4	:	@
~s	4	:	@
~d	4	:	-
~b	4	:	-
~o	4	:	-
~x	4	:	-
~r	5	:	@	:@
~p	0	:	@
~c	0	:	@
~f	5	-	@
~e	7	-	@
~g	7	-	@
~$	4	:	@	:@
~%	1	-	-
~&	1	-	-
~|	1	-	-
~~	1	-	-
~\n	0	:	@	-
~t	2	-	@	-
~*	1	:	@	-
~w	???
~?	0	-	@	-
~(	0	:	@	:@
~[	1→	:0	@0	-
~{ 	1	:	@	:@
~^	3	:	-

* Scrapbook : ブザーの鳴らないLinuxマシン(Beepオフ)

http://homepage2.nifty.com/ssfu/others/computer/linux_silence.html