Created
September 1, 2018 13:41
-
-
Save lostrepo/b878b39e80f4c5fb22e63257c4bf2dff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get postitive sequence values | |
// n - index of value in sequence | |
// x - array of values describing function | |
// general function: f(n) = f(n - x[0]) + f(n - x[1]) + ... + f(n - x[m]); f(0) = 1; | |
function stair(n, x, cache) | |
{ | |
cache = cache || [1]; | |
if (cache[n]){ | |
return cache[n]; | |
} | |
if (n < 0){ | |
return 0; | |
} | |
var res = 0; | |
for (var k in x){ | |
res += stair(n - x[k], x, cache); | |
} | |
document.write('Possible arrange ways for n='+ n +': '+ res +'<br>'); | |
cache[n] = res; | |
return res; | |
} | |
document.write('<h3>'+ stair(5000, [10]) +'</h3>'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment