09 Intro to combinations#

%%html
<iframe width="700" height="400" src="https://www.youtube.com/embed/iKy-d5_erhI/" frameborder="0" allowfullscreen></iframe>
import itertools
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
import seaborn as sns
from scipy import stats, special

khanacademy

Intro to combinations fig 1

persons = ['A', 'B', 'C', 'D', 'E', 'F']
seats = [1, 2, 3]
p = list(itertools.permutations(persons, len(seats)))
p
[('A', 'B', 'C'),
 ('A', 'B', 'D'),
 ('A', 'B', 'E'),
 ('A', 'B', 'F'),
 ('A', 'C', 'B'),
 ('A', 'C', 'D'),
 ('A', 'C', 'E'),
 ('A', 'C', 'F'),
 ('A', 'D', 'B'),
 ('A', 'D', 'C'),
 ('A', 'D', 'E'),
 ('A', 'D', 'F'),
 ('A', 'E', 'B'),
 ('A', 'E', 'C'),
 ('A', 'E', 'D'),
 ('A', 'E', 'F'),
 ('A', 'F', 'B'),
 ('A', 'F', 'C'),
 ('A', 'F', 'D'),
 ('A', 'F', 'E'),
 ('B', 'A', 'C'),
 ('B', 'A', 'D'),
 ('B', 'A', 'E'),
 ('B', 'A', 'F'),
 ('B', 'C', 'A'),
 ('B', 'C', 'D'),
 ('B', 'C', 'E'),
 ('B', 'C', 'F'),
 ('B', 'D', 'A'),
 ('B', 'D', 'C'),
 ('B', 'D', 'E'),
 ('B', 'D', 'F'),
 ('B', 'E', 'A'),
 ('B', 'E', 'C'),
 ('B', 'E', 'D'),
 ('B', 'E', 'F'),
 ('B', 'F', 'A'),
 ('B', 'F', 'C'),
 ('B', 'F', 'D'),
 ('B', 'F', 'E'),
 ('C', 'A', 'B'),
 ('C', 'A', 'D'),
 ('C', 'A', 'E'),
 ('C', 'A', 'F'),
 ('C', 'B', 'A'),
 ('C', 'B', 'D'),
 ('C', 'B', 'E'),
 ('C', 'B', 'F'),
 ('C', 'D', 'A'),
 ('C', 'D', 'B'),
 ('C', 'D', 'E'),
 ('C', 'D', 'F'),
 ('C', 'E', 'A'),
 ('C', 'E', 'B'),
 ('C', 'E', 'D'),
 ('C', 'E', 'F'),
 ('C', 'F', 'A'),
 ('C', 'F', 'B'),
 ('C', 'F', 'D'),
 ('C', 'F', 'E'),
 ('D', 'A', 'B'),
 ('D', 'A', 'C'),
 ('D', 'A', 'E'),
 ('D', 'A', 'F'),
 ('D', 'B', 'A'),
 ('D', 'B', 'C'),
 ('D', 'B', 'E'),
 ('D', 'B', 'F'),
 ('D', 'C', 'A'),
 ('D', 'C', 'B'),
 ('D', 'C', 'E'),
 ('D', 'C', 'F'),
 ('D', 'E', 'A'),
 ('D', 'E', 'B'),
 ('D', 'E', 'C'),
 ('D', 'E', 'F'),
 ('D', 'F', 'A'),
 ('D', 'F', 'B'),
 ('D', 'F', 'C'),
 ('D', 'F', 'E'),
 ('E', 'A', 'B'),
 ('E', 'A', 'C'),
 ('E', 'A', 'D'),
 ('E', 'A', 'F'),
 ('E', 'B', 'A'),
 ('E', 'B', 'C'),
 ('E', 'B', 'D'),
 ('E', 'B', 'F'),
 ('E', 'C', 'A'),
 ('E', 'C', 'B'),
 ('E', 'C', 'D'),
 ('E', 'C', 'F'),
 ('E', 'D', 'A'),
 ('E', 'D', 'B'),
 ('E', 'D', 'C'),
 ('E', 'D', 'F'),
 ('E', 'F', 'A'),
 ('E', 'F', 'B'),
 ('E', 'F', 'C'),
 ('E', 'F', 'D'),
 ('F', 'A', 'B'),
 ('F', 'A', 'C'),
 ('F', 'A', 'D'),
 ('F', 'A', 'E'),
 ('F', 'B', 'A'),
 ('F', 'B', 'C'),
 ('F', 'B', 'D'),
 ('F', 'B', 'E'),
 ('F', 'C', 'A'),
 ('F', 'C', 'B'),
 ('F', 'C', 'D'),
 ('F', 'C', 'E'),
 ('F', 'D', 'A'),
 ('F', 'D', 'B'),
 ('F', 'D', 'C'),
 ('F', 'D', 'E'),
 ('F', 'E', 'A'),
 ('F', 'E', 'B'),
 ('F', 'E', 'C'),
 ('F', 'E', 'D')]
len(p)
120
c = list(itertools.combinations(persons, len(seats)))
c
[('A', 'B', 'C'),
 ('A', 'B', 'D'),
 ('A', 'B', 'E'),
 ('A', 'B', 'F'),
 ('A', 'C', 'D'),
 ('A', 'C', 'E'),
 ('A', 'C', 'F'),
 ('A', 'D', 'E'),
 ('A', 'D', 'F'),
 ('A', 'E', 'F'),
 ('B', 'C', 'D'),
 ('B', 'C', 'E'),
 ('B', 'C', 'F'),
 ('B', 'D', 'E'),
 ('B', 'D', 'F'),
 ('B', 'E', 'F'),
 ('C', 'D', 'E'),
 ('C', 'D', 'F'),
 ('C', 'E', 'F'),
 ('D', 'E', 'F')]
len(c)
20
special.perm(6, 3) 
120.0
special.perm(6, 3) / np.math.factorial(3)
20.0
special.comb(6, 3)
20.0