CMPS-224 Lab 9 EXTRA CREDIT

Eddie Rangel
Department of Computer and Electrical Engineering and Computer Science
California State University, Bakersfield

Introduction

Goals: Solving Combinations in Python

Resources: Python 3 Documentation Documentation

Objective: Compute C(n,k) = n! / ((n-k)! k!)

Definition: An r-combination of elements of a set is an unordered selection of r elements from the set. Thus, an r-combination is simply a subset of the set with r elements. The number of r-combinations of a set with n distinct elements is denoted by C(n, r).

Write a program that has a function def Combination(n, k) that computes 'n choose k' (the combination of n things taken k at a time) using the definition for C(n,k):

        C(n,k) = n! / ((n-k)! k!)
    

You will need to use the recursive factorial function from Lab 6 to solve the factorials.

            n! = n * (n-1)!
            n! = 1 if n = 0 or n = 1 
            Example:
            5! = 5 * 4 * 3 * 2 * 1 = 120
        

Your Combination function will call the factorial function that you wrote in Lab 6.

Conditions of Satisfaction:

    
    $ python lab9.py
    6! = 720 
    4! = 24
    C(6,4) = 720/(2 * 24) = 15
    
    


What to turn in

Show the programs running to me or our TA.