CS2322
Laboratory Problem 32
Combinations
It can be shown that (pascal-triangle n k) represents the number of different ways k objects can be selected from a list of n distinct objects. This number is often denoted by ( nk). The notation n! is used for the factorial of n, which we compute with the function fact.
(define (fact x)
(if (<= x 1)
1
(* x (fact (- x 1)))))
It can be shown that the number (nk) can be computed using the formula n!/k!(n-k)!. Write the definition of a procedure combinations that uses this formula instead of the algorithm given in Laboratory Problem 31. Compare the expected performance of combinations with pascal-triangle. Compute (combinations 1000 500).
Lab 32 Scheme Code