自然数の分割
Posted feedbacks - Emacs Lisp
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))
|




herumi
#4099()
Rating1/1=1.00
[ reply ]