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)
)
)
)
)