Created
November 16, 2011 22:06
-
-
Save jakedobkin/1371619 to your computer and use it in GitHub Desktop.
Euler 15
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
| #!/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