Skip to content

Instantly share code, notes, and snippets.

@nektro
Last active October 16, 2017 02:25
Show Gist options
  • Save nektro/fa8027f5ae189d4ced9afb7611cc5c40 to your computer and use it in GitHub Desktop.
Save nektro/fa8027f5ae189d4ced9afb7611cc5c40 to your computer and use it in GitHub Desktop.
algorithm 3.2
function bin2(n, k)
{
const B = new Array(n+1).fill(0).map((x) => {
return new Array(k+1).fill(0);
});
for (let i = 0; i <= n; i++) {
for (let j = 0; j <= Math.min(i,k); j++) {
if (j === 0 || j === i) {
B[i][j] = 1;
}
else {
B[i][j] = B[i-1][j-1] + B[i-1][j];
}
}
}
return B[n][k];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment