p031.scm 536 B

123456789101112131415161718192021
  1. (ns (euler solved p031))
  2. (use (argyle))
  3. (def coins '(200 100 50 20 10 5 2 1))
  4. ;;; This is how we want to write it
  5. (def coin-sums1
  6. (fn-case
  7. ((amount (coin)) 1)
  8. ((amount :o ((coin . rest) :or coins))
  9. (loop rec ((amount amount))
  10. (+ (rec (- amount coin))
  11. (coin-sums amount rest))))))
  12. (def coin-sums2 (amount :o ((coin . rest) :or coins))
  13. (if (nil? rest) 1
  14. (loop rec ((amount amount))
  15. (if (neg? amount) 0
  16. (+ (rec (- amount coin))
  17. (coin-sums2 amount rest))))))