Sum of Consecutive
(defun iota (num) (loop for n from 1 upto num collect n)) (defun get-all-pattern (num) (let ((seq (iota (1+ (floor num 2))))) (loop for pat in (loop for i from 0 upto (1- (length seq)) append (loop for j from (+ 2 i) upto (length seq) collect (subseq seq i j))) count (= num (apply #'+ pat))))) (defun main () (loop for num = (read) until (zerop num) do (format t "~A~%" (get-all-pattern num))))
可能性がある最大値を決定して、それまでの全部分リストにたいして検索。