I want to program a function to find C (n, k) using tail recursion, and I would really appreciate your help.
I have achieved this:
(defun tail-recursive-binomial (n k)
(cond ((or (< n k) (< k 0)) NIL)
((or (= k 0) (= n k)) 1)
(T (* (tail-recursive-binomial (- n 1) (- k 1)) (/ n k)))))
Using the following property of binomial coefficients .
But I do not know how to make a recursive call the last command executed by each instance, since the latter is a product. I am trying to use it with a helper function, which, in my opinion, is the only way, but I have not found a solution.
source
share