Skip to content

Instantly share code, notes, and snippets.

@gavinsykes
Created December 9, 2019 22:22
Show Gist options
  • Save gavinsykes/532e9dd88b7d77c6e15cda7df7fa8053 to your computer and use it in GitHub Desktop.
Save gavinsykes/532e9dd88b7d77c6e15cda7df7fa8053 to your computer and use it in GitHub Desktop.
Project Euler Problem 15 in JavaScript
const euler_15 = n => nCr(2*n,n);
const nCr = (n,r) => {
if (r > n || n < 1 || r < 1) {
return undefined;
}
return factorial(n) / (factorial(r) * factorial(n-r));
};
const factorial = num => {
let result = 1,
n = +num;
while (n > 1) {
n--;
result *= n;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment