Combinatoric 'N Choose R' In Java Math?
Answer : The Formula It's actually very easy to compute N choose K without even computing factorials. We know that the formula for (N choose K) is: N! -------- (N-K)!K! Therefore, the formula for (N choose K+1) is: N! N! N! N! (N-K) ---------------- = --------------- = -------------------- = -------- x ----- (N-(K+1))!(K+1)! (N-K-1)! (K+1)! (N-K)!/(N-K) K!(K+1) (N-K)!K! (K+1) That is: (N choose K+1) = (N choose K) * (N-K)/(K+1) We also know that (N choose 0) is: N! ---- = 1 N!0! So this gives us an easy starting point, and using the formula above, we can find (N choose K) for any K > 0 with K multiplications and K divisions. Easy Pascal's Triangle Putting the above together, we can easily generate Pascal's triangle as follows: for (int n = 0; n < 10; n++) { int nCk = 1; for (int k = 0; k <= n; k++) { System.out.print(nCk +...