하물며, 리턴값 자동 출력을 막는 방법을 몰라서 정답은 "SUM" 프리픽스를 붙여서 출력...
;;
;; http://okky.kr/article/278566
;;
;; http://frostlab.net/2015/05/09/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour/
;;
;; problem 1
(defun sum-of-list-using-recursion (lst)
(if (null lst)
0
(+ (car lst) (sum-of-list-using-recursion (cdr lst)))))
;; problem 2
(defun merge-two-list (lst1 lst2)
(mapcar #'cons lst1 lst2))
;; problem 3
(defun fibonacci (num)
(if (= num 0)
0
(if (= num 1)
1
(+ (fibonacci (- num 2)) (fibonacci (- num 1))))))
;; problem 4
;; 문제를 잘 못 이해한 것 같다.
;; 각 입력된 순사 단위로 조합해야 하는데, 각 숫자를 1자리로 나눠서 사용했다;
(defun make-big-number (token-list)
(let ((num-list
(apply #'append
(mapcar
(lambda (x) (coerce (write-to-string x) 'list))
token-list))))
(mapc #'princ (sort num-list #'char>))))
;; problem 5
(defconstant *hundred* 100)
(defparameter *data* '(1 2 3 4 5 6 7 8 9))
(defun num-lst-from-lst (lst)
(mapcar #'reverse (reverse (maplist #'print (reverse lst)))))
(defun number-from-num-lst (num-lst)
(parse-integer
(with-output-to-string (stream)
(mapcar (lambda (ch) (princ ch stream)) num-lst))))
(defun build-hundred (pre-sum op lst stack)
(if (null lst)
(if (= pre-sum *hundred*)
(format t "~%SUM: ~a, equation: ~A" pre-sum (butlast stack))
(values))
(let ((lst-component (num-lst-from-lst lst)))
(mapcar (lambda (x)
(let* ((num (number-from-num-lst x))
(sum (funcall op pre-sum num))
(tail (sort (set-exclusive-or x lst) #'<)))
(build-hundred sum #'+ tail (append stack `(,num +)))
(build-hundred sum #'- tail (append stack `(,num -)))))
lst-component)
(values))))
(defun make-hundred ()
(build-hundred 0 #'+ *data* nil))