Created
January 20, 2015 03:23
-
-
Save nramirez/8ec3dc900f5fd66e1503 to your computer and use it in GitHub Desktop.
Explosive Sum
This file contains hidden or 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
var sum = function(number){ | |
return p(number, number); | |
} | |
var memo = []; | |
var p = function (n, m){ | |
if (m == 0 ) { return 0;}; | |
if (n == 0) { return 1}; | |
if (n < 0) { return 0}; | |
if (memo[n] == undefined) memo[n] = []; | |
var result = memo[n][m]; | |
if (typeof result != 'number') { | |
result = p(n-m, m) + p(n, m-1); | |
memo[n][m] = result; | |
}; | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment