Skip to content

Instantly share code, notes, and snippets.

@naush
Created July 14, 2010 15:21
Show Gist options
  • Save naush/475544 to your computer and use it in GitHub Desktop.
Save naush/475544 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 (var 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