Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created November 16, 2011 22:06
Show Gist options
  • Select an option

  • Save jakedobkin/1371619 to your computer and use it in GitHub Desktop.

Select an option

Save jakedobkin/1371619 to your computer and use it in GitHub Desktop.
Euler 15
#!/usr/local/bin/node
// number of paths is a combination 40C20, because you have to get there in 40 steps and make 20 choices along the way
// that's n! / k! (n-k)!
n = 40;
k = 20;
nminusk = n-k;
n_factorial = 1;
k_factorial = 1;
nminusk_factorial = 1;
for(i=n;i>0; i--)
{
n_factorial*=i;
}
for (j=k;j>0;j--)
{
k_factorial*=j;
}
for (l=nminusk;l>0;l--)
{
nminusk_factorial*=l;
}
answer = n_factorial / (k_factorial * nminusk_factorial);
console.log(n +"choose" + k + "is equal to " + answer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment