Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,19 @@
function countcoins(t, o) {
'use strict';
var targetsLength = t + 1;
var operandsLength = o.length;
t = [1];
for (var a = 0; a < operandsLength; a++) {
for (var b = 1; b < targetsLength; b++) {
// initialise undefined target
t[b] = t[b] ? t[b] : 0;
// accumulate target + operand ways
t[b] += (b < o[a]) ? 0 : t[b - o[a]];
}
}
return t[targetsLength - 1];
}

View file

@ -0,0 +1,2 @@
countcoins(100, [1,5,10,25]);
242

View file

@ -0,0 +1,25 @@
function countcoins(t, o) {
'use strict';
var operandsLength = o.length;
var solutions = 0;
function permutate(a, x) {
// base case
if (a === t) {
solutions++;
}
// recursive case
else if (a < t) {
for (var i = 0; i < operandsLength; i++) {
if (i >= x) {
permutate(o[i] + a, i);
}
}
}
}
permutate(0, 0);
return solutions;
}

View file

@ -0,0 +1,2 @@
countcoins(100, [1,5,10,25]);
242

View file

@ -0,0 +1,8 @@
var amount = 100,
coin = [1, 5, 10, 25]
var t = [1];
for (t[amount] = 0, a = 1; a < amount; a++) t[a] = 0 // initialise t[0..amount]=[1,0,...,0]
for (var i = 0, e = coin.length; i < e; i++)
for (var ci = coin[i], a = ci; a <= amount; a++)
t[a] += t[a - ci]
document.write(t[amount])