QuantitativePrimer icon indicating copy to clipboard operation
QuantitativePrimer copied to clipboard

Suggestion for answer to question 23

Open dougmvieira opened this issue 6 years ago • 1 comments

Thanks a lot for the primer! When reading question 23, I thought the "recursion" part was meant on the binomial function itself instead of the factorial, so I came up with:

def n_given_k(n, k):
    if (k == 0) or (k == n):
        return 1
    return n_given_k(n - 1, k - 1) + n_given_k(n - 1, k)

For reference: https://en.wikipedia.org/wiki/Binomial_coefficient#Recursive_formula

It answers the question, although it is of course very inefficient. A better recursive formula is given in http://penguin.ewu.edu/~trolfe/BinomialCoeff/ .

dougmvieira avatar Feb 18 '20 03:02 dougmvieira

This is very helpful, thanks. I will see whether I can work it into the next version.

dwcoder avatar Mar 10 '20 07:03 dwcoder