Last active
August 29, 2015 14:07
-
-
Save ara-ta3/3c7d403f039bf1244709 to your computer and use it in GitHub Desktop.
This file contains 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
(define (selectOptimalCoupons amount myCouponList) | |
(consume amount (sort myCouponList >) (list)) | |
) | |
(define (consume amount coupons usedCoupons) | |
(if (null? coupons) | |
usedCoupons | |
(if (>= amount (car coupons)) | |
(consume (- amount (car coupons)) (cdr coupons) (append usedCoupons (list (car coupons)))) | |
(consume amount (cdr coupons) usedCoupons)) | |
) | |
) | |
(print (selectOptimalCoupons 100 '())) | |
(print (selectOptimalCoupons 100 '(50 50 100))) | |
(print (selectOptimalCoupons 470 '(50 50 50 100 100 100 100 100 500))) | |
(print (selectOptimalCoupons 1230 '(50 50 50 50 50 50 100 100 100 100 100 100 500 500))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment