みよ #4316(2007/11/22 03:24 GMT) [ Emacs Lisp ] Rating0/0=0.00
comprehensionって便利ですね。 List Comprehension - defmacro によるリストの内包表記 http://lambda.s55.xrea.com/Emacs.html のlist-of を利用してemacs-lispで書いてみました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
(defun partitionNum (a b) (if (= b 1) (list (list a)) (let ((x 0) (l '())) (while (<= x a) (progn (setq l (append l (list-of (append (list (- a x)) y) (y in (partitionNum x (- b 1)))))) (setq x (+ x 1)))) l))) (print (partitionNum 5 3))
Rating0/0=0.00-0+
1 reply [ reply ]
みよ
#4316()
[
Emacs Lisp
]
Rating0/0=0.00
comprehensionって便利ですね。 List Comprehension - defmacro によるリストの内包表記 http://lambda.s55.xrea.com/Emacs.html のlist-of を利用してemacs-lispで書いてみました。
(defun partitionNum (a b) (if (= b 1) (list (list a)) (let ((x 0) (l '())) (while (<= x a) (progn (setq l (append l (list-of (append (list (- a x)) y) (y in (partitionNum x (- b 1)))))) (setq x (+ x 1)))) l))) (print (partitionNum 5 3))Rating0/0=0.00-0+