* Menu
[[About:self:AboutPage.txt]] | [[Profile:file/southly/]] | [[まとめ:self:1163859357.txt]] | [[オリジナル:http://ninjinix.x0.com/rn/]] | [[xyzzy:lisp/]] | [[あんてな:listall]] | [[■:lisp]] | [[buzz:files/southly#buzz]]
- 素数を求める
- 素数を求める
- 2006-06-22
- 素数を求める。
- xyzzy lisp : format ~X
- xyzzy lisp : format ~D
- Scrapbook : template
- xyzzy lisp : format ~O
- xyzzy lisp : format ~B
- Scrapbook : C/C++向け多倍長整数資料を探している人のためのガイド @ 2005年10月 @ ratio - rational - irrational @ IDM
- Scrapbook : soft/Xming - ペンギンの杜 - Linuxソフトライブラリ -
- Scrapbook : エレベーター事故まとめ
- xyzzy lisp : formatのCONTROL-STRINGとパラメータと「:」と「@」の関係
- Scrapbook : ブザーの鳴らないLinuxマシン(Beepオフ)
page 22 - << : 0 : 1 : 2 : 3 : 4 : 5 : 6 : 7 : 8 : 9 : 10 : 11 : 12 : 13 : 14 : 15 : 16 : 17 : 18 : 19 : 20 : 21 : 22 : 23 : 24 : 25 : 26 : 27 : 28 : 29 : 30 : 31 : 32 : 33 : 34 : 35 : 36 : 37 : 38 : >>
* 素数を求める
素直に再帰
(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らしく。
より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
- 整数データの16進表記
- ":X" カンマ区切り
- "@X" 常に符号付き
- ":@X" 上記の組み合わせ
- パラメータは最大4つ
- 最小桁(幅)
- 足りない空きを埋める文字
- 区切りに使う文字
- 区切りを入れる間隔
- 後ろ2つは":X"と":@X"のときのみ有効。"X"と"@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
- 整数データの10進表記
- ":D" カンマ区切り
- "@D" 常に符号付き
- ":@D" 上記の組み合わせ
- パラメータは最大4つ
- 最小桁(幅)
- 足りない空きを埋める文字
- 区切りに使う文字(いわゆる全角文字は想定されていない。最小桁がおかしくなる)
- 区切りを入れる間隔
- 後ろ2つは":D"と":@D"のときのみ有効。"D"と"@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"