Skip to content

Instantly share code, notes, and snippets.

@timrwood
Created November 3, 2011 01:04
Show Gist options
  • Save timrwood/1335476 to your computer and use it in GitHub Desktop.
Save timrwood/1335476 to your computer and use it in GitHub Desktop.
140 bytes change making
function x(total, values, place) {
var output = i = 0,
f = function(i){
output += (i == total);
};
while (place = values[i++]) {
(function(b,c){
f = function(a, i){
for (i = a; i <= total; i += b){
c(i);
}
};
})(place, f);
}
f(0);
return output;
}
console.log('total', x(100, [100,50,25,10,5,1]));
//console.log('total', x(100, [1,5,10,25,50,100]));
142 bytes
function x(a,b,c){var d=i=0,e=function(b){d+=b==a};while(c=b[i++])(function(b,c){e=function(d,e){for(e=d;e<=a;e+=b)c(e)}})(c,e);return e(0),d}
function x(a, b, c) {
var d = i = 0,
e = function (b) {
d += b == a
};
while (c = b[i++])(function (b, c) {
e = function (d, e) {
for (e = d; e <= a; e += b) c(e)
}
})(c, e);
return e(0), d
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment