transcendental-lisp/lisp/compound-interest.lisp

20 lines
404 B
Common Lisp

(defun decrement (n) (- n 1))
(defun percent (n percent)
(cond
((> percent 0) (/ (+ (* n percent) 50) 100))
(T (/ (- (* n percent) 50) 100))
)
)
(defun compound-interest (principal rate years)
(cond
((= years 0) principal)
(T (compound-interest (+ principal (percent principal rate))
rate
(decrement years)
)
)
)
)