mc #4713(2007/12/10 05:39 GMT) [ Common Lisp ] Rating1/1=1.00
全体のあみだくじの文字列をamidaに渡すと、結果の文字列を返します。
(princ
(amida
"A B C D E
| | |-| |
|-| | |-|
| |-| |-|
|-| |-| |
|-| | | |"))
;=>
A B C D E
|-| | | |
B D C A E
||<
1 2 3 4 5 6 7 8 9 10 11 12 13 14
(require :cl-ppcre) (defun amida (amida) (with-input-from-string (str amida) (let ((items (ppcre:split "\\s*" (read-line str nil nil)))) (do ((line (read-line str nil :eof) (read-line str nil :eof))) ((eq :eof line) (format nil "~A~%~{~A~^ ~}" amida items)) (exch line items))))) (defun exch (pat items) (do ((pos (ppcre:all-matches "-" pat) (cddr pos))) ((endp pos) items) (let ((p (truncate (car pos) 2))) (rotatef (nth p items) (nth (1+ p) items)))))
Rating1/1=1.00-0+
1 reply [ reply ]
mc #4714(2007/12/10 06:01 GMT) [ diff ] Rating0/0=0.00
すいません、間違った方を投稿しまいました。"\s*"じゃなくて、"\s+"でした。
1 2 3 4
5c5 < (let ((items (ppcre:split "\\s*" (read-line str nil nil)))) --- > (let ((items (ppcre:split "\\s+" (read-line str nil nil))))
Rating0/0=0.00-0+
[ reply ]
mc
#4713()
[
Common Lisp
]
Rating1/1=1.00
全体のあみだくじの文字列をamidaに渡すと、結果の文字列を返します。
(princ
(amida
"A B C D E
| | |-| |
|-| | |-|
| |-| |-|
|-| |-| |
|-| | | |"))
;=>
A B C D E
| | |-| |
|-| | |-|
| |-| |-|
|-| |-| |
|-| | | |
B D C A E
||<
(require :cl-ppcre) (defun amida (amida) (with-input-from-string (str amida) (let ((items (ppcre:split "\\s*" (read-line str nil nil)))) (do ((line (read-line str nil :eof) (read-line str nil :eof))) ((eq :eof line) (format nil "~A~%~{~A~^ ~}" amida items)) (exch line items))))) (defun exch (pat items) (do ((pos (ppcre:all-matches "-" pat) (cddr pos))) ((endp pos) items) (let ((p (truncate (car pos) 2))) (rotatef (nth p items) (nth (1+ p) items)))))Rating1/1=1.00-0+
1 reply [ reply ]