Created
June 22, 2010 09:15
-
-
Save naush/448222 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
| var minimum_number_of_stamps = function() { | |
| var memo = []; | |
| var min_stamps = function(postage, stamps) { | |
| if (postage == 0) { | |
| return 0; | |
| } else if (memo[postage]) { | |
| return memo[postage]; | |
| } else { | |
| var min = postage; | |
| for (i = 0; i < stamps.length; i++) { | |
| if (stamps[i] <= min) { | |
| number = 1 + min_stamps(postage - stamps[i], stamps); | |
| if (number < min) { | |
| min = number; | |
| } | |
| } | |
| } | |
| } | |
| memo[postage] = min; | |
| return min; | |
| }; | |
| return min_stamps; | |
| }(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment