Created
April 27, 2019 03:01
-
-
Save takeokunn/451a3c3a5fdd2dff93199126cf0bf5c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defparameter *coins* `(1 5 10 50 100 500)) | |
(defparameter *have-coins* `(3 2 1 3 0 2)) | |
(defparameter *sum* 620) | |
(defun calc (index sum answer) | |
(let* ((number (min (floor sum (nth index *coins*)) (nth index *have-coins*))) | |
(new-sum (- sum (* number (nth index *coins*)))) | |
(new-answer (+ answer number))) | |
(values new-sum new-answer))) | |
(defun coins (index sum answer) | |
(if (equalp index -1) | |
answer | |
(multiple-value-bind (new-sum new-answer) (calc index sum answer) | |
(coins (1- index) new-sum new-answer)))) | |
(defun solve () | |
(let ((total (coins 5 *sum* 0))) | |
(format nil "~D" total))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment