RosettaCodeData/Task/Count-the-coins/Common-Lisp/count-the-coins-2.lisp
2015-02-20 00:35:01 -05:00

6 lines
272 B
Common Lisp

(defun count-change (amount coins &aux (ways (make-array (1+ amount) :initial-element 0)))
(setf (aref ways 0) 1)
(loop for coin in coins do
(loop for j from coin upto amount
do (incf (aref ways j) (aref ways (- j coin)))))
(aref ways amount))