Skip to content

Instantly share code, notes, and snippets.

@naush
Created June 22, 2010 09:15
Show Gist options
  • Save naush/448222 to your computer and use it in GitHub Desktop.
Save naush/448222 to your computer and use it in GitHub Desktop.
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