# n is the row, and k is the position along the row. def n_choose_k(n,k): if n <= 1 or k <= 0 or k >= n: return 1 return n_choose_k(n-1,k-1) + n_choose_k(n-1,k)