transcendental-lisp/lisp/finance/compound-interest.lisp

15 lines
392 B
Common Lisp
Raw Normal View History

(defun decrement (n) (- n 1))
2017-03-06 11:00:18 -05:00
(defun percent-of-number (n percentage)
2017-03-04 16:33:05 -05:00
(if (> percentage 0)
(/ (+ (* n percentage) 50) 100)
2017-03-06 11:00:18 -05:00
(/ (- (* n percentage) 50) 100)))
2017-03-04 16:33:05 -05:00
(defun compound-interest (principal interest-rate years)
(if (< years 1)
principal
2017-03-03 15:06:49 -05:00
(compound-interest
2017-03-06 11:00:18 -05:00
(+ principal (percent-of-number principal interest-rate))
2017-03-04 16:33:05 -05:00
interest-rate
2017-03-06 11:00:18 -05:00
(decrement years))))