September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

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

View file

@ -1,25 +1,25 @@
function countcoins(t, o) {
'use strict';
var operandsLength = o.length;
var solutions = 0;
'use strict';
var operandsLength = o.length;
var solutions = 0;
function permutate(a, x) {
function permutate(a, x) {
// base case
if (a === t) {
solutions ++;
}
// 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);
}
}
}
}
// 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;
permutate(0, 0);
return solutions;
}

View file

@ -1,6 +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] )
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])