Skip to content

Instantly share code, notes, and snippets.

@pimiento
Last active January 15, 2023 06:03
Show Gist options
  • Save pimiento/05e2297358c65e2bf91eb71463747445 to your computer and use it in GitHub Desktop.
Save pimiento/05e2297358c65e2bf91eb71463747445 to your computer and use it in GitHub Desktop.
#!/usr/bin/sbcl --script
(defun count-change (amount)
(cc amount 5))
(defun cc (amount kinds-of-coins)
(cond ((= amount 0) 1)
((or (< amount 0) (= kinds-of-coins 0)) 0)
(t (+ (cc amount
(- kinds-of-coins 1))
(cc (- amount
(first-denomination kinds-of-coins))
kinds-of-coins)))))
(defun first-denomination (kinds-of-coins)
(cond ((= kinds-of-coins 1) 1)
((= kinds-of-coins 2) 5)
((= kinds-of-coins 3) 10)
((= kinds-of-coins 4) 25)
((= kinds-of-coins 5) 50)))
(trace cc)
(count-change 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment