I've added 2 more problems to the Sagetex: Combinatorics/Probability page. The problem above has the form:
A high school committee of 6 is to be made from 32 boys and 41 girls. Within this set of students there are 2 senior boys and 3 senior girls. How many committees of 3 boys and 3 girls are there that contain at least one senior boy and one senior girl?
It's worth noting an interesting aspect of this problem: in order to properly count, the various cases need to be listed and this means the output of the solution will be dynamic in the sense that the number of cases to be listed changes in the solution will change depending on our specific number of senior boys and girls. In the case of 2 senior boys and 3 senior girls we need to throw out committees with
- no senior boy and no senior girl
- no senior boy and 1 senior girl
- no senior boy and 2 senior girls
- no senior boy and 3 senior girls
- no senior girl and 1 senior boy
- no senior girl and 2 senior boy
Change the number of senior girls or senior boys and that list given in the solution changes.
The output of the various cases is handled in the sagesilent block. We need to avoid counting no senior boy and no senior girl twice, so no senior boy and no senior girl is calculated here:
NoSeniors = binomial(girls-Sgirls,3)*binomial(boys-Sboys,3)
and 2 FOR loops create the rest of the cases. Here the committees with 0 senior girls are all created
for i in range(1,Sboys+1):
output += r"$0$ senior girls and $%s$ senior boys: $C(%s, 3)\cdot C(%s,%s)\cdot C(%s,%s)$\\"%(i,girls-Sgirls,Sboys,i,boys-Sboys,3-i)
remove += binomial(girls-Sgirls,3)*binomial(Sboys,i)*binomial(boys-Sboys,3-i)
A similar loop handles 0 senior boys. Note that 3 is hard coded. That's the number of girls (and boys on the committee). Increasing that number will make too many cases to enumerate for a test. Likewise
Sboys = Integer(randint(2,3))
Sgirls = Integer(randint(2,3))
keeps the problem size more reasonable as well; 6 cases is enough and, depending on the ability of your class, it might be more appropriate to decrease the number of cases; i.e., make the hard coded 3 a two.